question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Underscore('_') removal too arbitrary in _safe_attr

See original GitHub issue

Consider 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:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cdgriffithcommented, Jun 4, 2019

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.

0reactions
cdgriffithcommented, Dec 25, 2019

Fixed in 4.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found