-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crash when tring to replace None value in a list #92
Comments
adding possibility to use integer as list indices in newly created lists (dpath-maintainers#91) and fixing issue dpath-maintainers#92
Can you check your code against te latest version and see if your issue is resolved? |
In 2.0 this happens because import dpath.util
a={}
print(a)
dpath.util.new(a, ['b'], [])
print(a)
dpath.util.new(a, ['b',3], 5)
print(a)
dpath.util.set(a, ['b',1], {})
print(a)
dpath.util.new(a, ['b',1,"c"], 5)
print(a) Which outputs:
You can avoid the situation entirely if you create lists in order. |
This potentially could be made more user friendly by instead filling with a sentinel value. |
The 2.0 error message is significantly more comprehensible than the 1.x error message, which is a ValueError. According to the documentation, lists are created by new() up to the index given, and are filled with None, not more mappings. new() sees a string key and assumes you are trying to set a key in a mapping, and proceeds to give a list a character it can't index. ValueError results. +1 for the sentinel value, I tried a few creative ways to do it with the functionality already in 1.0 and it was prohibitively difficult. |
Blocked by #136 |
a={}
dpath.util.new(a, ['b'], [])
dpath.util.new(a, ['b',3], 5)
dpath.util.new(a, ['b',1,"c"], 5)
creates error invalid literal for int() with base 10: 'c' lin 32 oin path.py ( result.append([path[-1], cur[int(path[-1])].class]))
The text was updated successfully, but these errors were encountered: