This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Takuo Matsuoka
Recipients Takuo Matsuoka
Date 2022-03-27.11:17:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648379876.09.0.993153417089.issue47136@roundup.psfhosted.org>
In-reply-to
Content
In the creation of a class, it looks as if the value of the variable
__name__ gets assigned automatically to the variable __module__ in the
class body.  However, the correct name space where the value of
__name__ should be looked up is NOT the mapping object returned by the
method __prepare__
of the metaclass.  In the class body, the programmer may use the
variable __name__ for some other purposes, and might not notice
__module__ was messed up.  Here's a code which produces a problem.

```
class C(type):
    @classmethod
    def __prepare__(cls, /, *args, **kwargs):
        return dict(__name__ = "whatever")

class O(metaclass=C):
    print(__module__) # "whatever" printed
```

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.
History
Date User Action Args
2022-03-27 11:17:56Takuo Matsuokasetrecipients: + Takuo Matsuoka
2022-03-27 11:17:56Takuo Matsuokasetmessageid: <1648379876.09.0.993153417089.issue47136@roundup.psfhosted.org>
2022-03-27 11:17:56Takuo Matsuokalinkissue47136 messages
2022-03-27 11:17:55Takuo Matsuokacreate