gh-98886: Fix issues with dataclass fields with special underscore names#102032
gh-98886: Fix issues with dataclass fields with special underscore names#102032hauntsaninja merged 5 commits into
Conversation
This commit prefixes `__dataclass` to several things in the locals dict: - Names like _dflt_ (which cause trouble, see first test) - Names like _type_ (not known to be able to cause trouble) - _return_type (not known to able to cause trouble) - _HAS_DEFAULT_FACTORY (which causes trouble, see second test) In addition, this removes `MISSING` from the locals dict. As far as I can tell, this wasn't needed even in the initial implementation of dataclasses.py (and tests on that version passed with it removed). This is basically a continuation of python#96151, where fixing this was welcomed in python#98143 (comment)
|
The name you eventually settled on for What do you think about changing all the names in this PR to have both leading and trailing underscores? |
Sorry, something went wrong.
|
Thanks, fixed! |
Sorry, something went wrong.
carljm
left a comment
There was a problem hiding this comment.
LGTM. I agree the MISSING thing is a bit odd, but I examined the code for _init_fn and the functions it calls (_init_param and _field_init) and I can't see any way for MISSING to show up in the text of the init function to create. And clearly the tests pass without it.
Sorry, something went wrong.
…ore names (python#102032) This commit prefixes `__dataclass` to several things in the locals dict: - Names like `_dflt_` (which cause trouble, see first test) - Names like `_type_` (not known to be able to cause trouble) - `_return_type` (not known to able to cause trouble) - `_HAS_DEFAULT_FACTORY` (which causes trouble, see second test) In addition, this removes `MISSING` from the locals dict. As far as I can tell, this wasn't needed even in the initial implementation of dataclasses.py (and tests on that version passed with it removed). This makes me wary :-) This is basically a continuation of python#96151, where fixing this was welcomed in python#98143 (comment)
…ore names (python#102032) This commit prefixes `__dataclass` to several things in the locals dict: - Names like `_dflt_` (which cause trouble, see first test) - Names like `_type_` (not known to be able to cause trouble) - `_return_type` (not known to able to cause trouble) - `_HAS_DEFAULT_FACTORY` (which causes trouble, see second test) In addition, this removes `MISSING` from the locals dict. As far as I can tell, this wasn't needed even in the initial implementation of dataclasses.py (and tests on that version passed with it removed). This makes me wary :-) This is basically a continuation of python#96151, where fixing this was welcomed in python#98143 (comment)
This commit prefixes
__dataclassto several things in the locals dict:_dflt_(which cause trouble, see first test)_type_(not known to be able to cause trouble)_return_type(not known to able to cause trouble)_HAS_DEFAULT_FACTORY(which causes trouble, see second test)In addition, this removes
MISSINGfrom the locals dict. As far as I can tell, this wasn't needed even in the initial implementation of dataclasses.py (and tests on that version passed with it removed). This makes me wary :-)This is basically a continuation of #96151, where fixing this was welcomed in #98143 (comment)