Message416118
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. |
|
Date |
User |
Action |
Args |
2022-03-27 11:17:56 | Takuo Matsuoka | set | recipients:
+ Takuo Matsuoka |
2022-03-27 11:17:56 | Takuo Matsuoka | set | messageid: <1648379876.09.0.993153417089.issue47136@roundup.psfhosted.org> |
2022-03-27 11:17:56 | Takuo Matsuoka | link | issue47136 messages |
2022-03-27 11:17:55 | Takuo Matsuoka | create | |
|