Skip to content

Commit 4d82559

Browse files
A5rocksilevkivskyi
andauthored
Provide a fullname for __module__ (#20288)
Fixes #20284 --------- Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
1 parent a749368 commit 4d82559

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mypy/semanal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6511,7 +6511,9 @@ def _lookup(
65116511
implicit_node = node
65126512
# 2b. Class attributes __qualname__ and __module__
65136513
if self.type and not self.is_func_scope() and name in {"__qualname__", "__module__"}:
6514-
return SymbolTableNode(MDEF, Var(name, self.str_type()))
6514+
v = Var(name, self.str_type())
6515+
v._fullname = self.qualified_name(name)
6516+
return SymbolTableNode(MDEF, v)
65156517
# 3. Local (function) scopes
65166518
for table in reversed(self.locals):
65176519
if table is not None and name in table:

test-data/unit/check-classes.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8927,6 +8927,11 @@ class C:
89278927
__module__ # E: Name "__module__" is not defined
89288928
__qualname__ # E: Name "__qualname__" is not defined
89298929

8930+
x: __module__ # E: Variable "__main__.C.__module__" is not valid as a type \
8931+
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
8932+
y: __qualname__ # E: Variable "__main__.C.__qualname__" is not valid as a type \
8933+
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
8934+
89308935
[case testPropertySetterType]
89318936
class A:
89328937
@property

0 commit comments

Comments
 (0)