-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Dataclass with __module__ = "builtins"
adds __builtins__.__builtins__
#105203
Comments
It is normal for modules created from Python to have attribute 'builtins'. I am not surprised that one is added here, so I doubt that this is a bug. My recursive search of Lib/*.py failed to find @ericvsmith Is there any point to using dataclasses for custom exceptions? |
While that's true, it does seem very surprising to me that merely declaring a dataclass ends up dynamically adding a new attribute to an existing module, which wasn't there before. |
From a (very) quick reading of the dataclasses source, it looks like this is actually happening because >>> hasattr(__builtins__, "__builtins__")
False
>>> exec("", __builtins__.__dict__, {})
>>> hasattr(__builtins__, "__builtins__")
True And this behavior actually seems to be documented:
While that still seems rather surprising, I suppose that's working as documented then? |
Yes, this is because of the |
From what I can gather, it's a hack to see I have a feeling I've seen this hack used elsewhere before as well, but I can't remember where exactly. edit: Might have been this bit in pytest I'm thinking of. |
I see no CPython issue here. |
Irrespective of this particular issue, it seems like a bad idea to hide the type of an exception. |
You're right about the reason it was implemented this way. I found this hack exactly in the place in |
I don't think there's anything to do here, so I'm going to close this. |
Bug report
When a dataclass with
__module__ = "builtins"
is defined (which seems somewhat common for custom exception classes), this seems to result in a__builtins__
attribute to__builtins__
(which recursively points to the builtins module):results in:
This in turn results in an
import astroid.nodes
causing an endless recursion, in the original issues due to how schemathesis usesdataclasses
:Downstream reports:
Your environment
The text was updated successfully, but these errors were encountered: