__setitem__ key type check#5
__setitem__ key type check#5JakubBlaha wants to merge 7 commits intoCode0x58:masterfrom JakubBlaha:master
Conversation
|
Also sorry about all of the commits. I am quite new to working with git and don't really know how to clean it up... |
|
Thanks for reporting and working on this @JakubBlaha! I think the PR would disallow things like Re. using git, you can do things like |
|
Thanks a lot for rewriting so much of the code! Now I am even more exceited to use this amazing library. The only thing that this library is missing now is a support to directly append to lists stored in a json file. I would be really excited to work on this feture. I am unsure about few things and probably would need a bit of advice. Should I open a new issue? |
|
:D That PR may now allow you to do the direct appending in a sneaky way with slices: store.list = ["foo"]
# as long as the slice start is >= the list length this will work
store["list", 9999:] = ["bar"]
assert store.list == ["foo", "bar"]... I just had a play, and it looks like you just do: store.list = ["foo"]
# as long as the slice start is >= the list length this will work
store["list"] += ["bar"]
assert store.list == ["foo", "bar"]Adding to the README and a test to make sure all behaves as expected sounds good to me, maybe something like this: store.list = []
extension = [{"key": "value"}]
# make sure += happens
store["list"] += extension
store.list += extension
assert len(store.list) == 2
# make sure a deepcopy occurred
assert store.list[0] is not extension[0] |
|
This is interesting. I thought this would not work since you are using deepcopying. Line 166 in 542a3c3 Edit: I am talking about this: |
|
Given this magic method behaviour [src]:
I think As long as you use things like Tests may be best for making sure though |
Doing something like
resulted in the error
which didn't really tell what the problem is. Therefore I have added a check for the
nameparameter in the__setitem__method, which will now raise aTypeErrorif something other then astris used as a key.