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
The variable __module__ in the class body getting an undesirable value from __prepare__ of the metaclass #91292
Comments
|
In the creation of a class, it looks as if the value of the variable Consequently, >>> O.__module__
'whatever'The issue is different from but seems related to https://bugs.python.org/issue28869 I haven't figured out the exact relation. Thanks. |
Dunder names like You wouldn't write: class MyList(list):
__len__ = "Hello world!"and then be surprised that MyList is broken. You shouldn't be surprised if setting |
|
Thank you for your response. I think __name__ here is very different from __len__ . (1) Even if you set __name__ to what should be the right value, e.g., (2) Even if, in other cases, you do del __name__ at the end of the body of the class O, the problem remains unless you The behaviour is not documented as far as I could see. I think such a Thanks. |
|
I'm going to close this one since I failed to specify the issue https://bugs.python.org/issue47224 for a more specific issue. |
|
Takuo, please give us an example from real code so we can see the problem. |
|
Thank you Ethan for reopening this issue and closing the other one. Here is a description of a more specific issue, containing a more Context Problem Also, the problem means we can't safely enjoy the ability of Example Consequently, >>> O.__module__
<attribute '__name__' of 'type' objects>Thanks. P.S. |
|
You are using the same generic example -- it does show the issue you are concerned with, but offers no rational for why we should "fix" it -- in other words, we cannot tell if it's actually broken. Please provide an example of code you are actually using -- a trimmed down metaclass is fine, but it should show the kinds of names you are changing to, why you want to change the names, etc. Maybe this is a just a documentation issue, or maybe it's an overlooked case that should be supported in Python -- we cannot tell based solely on your generic example. |
|
Thank you Ethan for your comments. Sure, I was not familiar with how you measure the magnitude of the I might just say there may be circumstances where a not so thoughtful where she creates instances of the metaclass C by inheriting from: Another thing I can say is code that does something like that is not If the behaviour is not going to be changed, then I think the Thanks. |
|
It would be nice if the class creation process was documented a bit And the output in Python 3.10 is: My take on this is that if the key __name__ is not present, the value of But if '__name__' is a key in the mapping returned by __prepare__, it But in neither case does it get used to set the class __name__. I cannot decide whether or not this makes sense to me. |
|
The original poster (Takuo Matsuoka) here. Thank you for your analysis, Steven.
In the former case, the value of the global What's relevant to the latter case seems that the class
I think this makes any appropriate value for the key <class 'getset_descriptor'> which I would say can't be an appropriate value for neither the class |


Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: