Underscore('_') removal too arbitrary in _safe_attr
See original GitHub issueConsider this code:
from box import Box
b = Box(_out = 'preserved')
b.update({'out': 'updated'})
# expected:
# {'_out': 'preserved', 'out': 'updated'}
# observed:
# {'_out': 'updated'}
# out lost
I thought this was designed intentionally at the beginning. However, when I digged into the code, I found the problem was due to https://github.com/cdgriffith/Box/blob/master/box.py#L151
out = ''
for character in attr:
out += character if character in allowed else "_"
out = out.strip("_") <- L151
This arbitrarily removed all underscores in the key, even the originally assigned ones.
I won’t say this is a bug, but really confusing.
Maybe we could use some unique characters to replace the characters that are not allowed, which will be removed later.
Say:
out = ''
for character in attr:
out += character if character in allowed else "@"
out = out.strip("@")
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Disable leading underscore removal in attrs auto ...
attr strips leading underscore from attribute names for the generated __init__ method . Is there a way to override that for a particular ......
Read more >Arbitrary Definition & Meaning
The meaning of ARBITRARY is existing or coming about seemingly at random or by chance or as a capricious and unreasonable act of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After thinking about it some more, this is going to have to hold off until a major release. It is a bug fix, however any exiting code that uses entities like these would break on update. I am actively working on 4.0 and will slate it for that.
Fixed in 4.0