File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -5569,7 +5569,7 @@ def lookup(
5569
5569
if not suppress_errors :
5570
5570
self .name_not_defined (name , ctx )
5571
5571
return None
5572
- # 2 . Class attributes (if within class definition)
5572
+ # 2a . Class attributes (if within class definition)
5573
5573
if self .type and not self .is_func_scope () and name in self .type .names :
5574
5574
node = self .type .names [name ]
5575
5575
if not node .implicit :
@@ -5579,6 +5579,9 @@ def lookup(
5579
5579
# Defined through self.x assignment
5580
5580
implicit_name = True
5581
5581
implicit_node = node
5582
+ # 2b. Class attributes __qualname__ and __module__
5583
+ if self .type and not self .is_func_scope () and name in {"__qualname__" , "__module__" }:
5584
+ return SymbolTableNode (MDEF , Var (name , self .str_type ()))
5582
5585
# 3. Local (function) scopes
5583
5586
for table in reversed (self .locals ):
5584
5587
if table is not None and name in table :
Original file line number Diff line number Diff line change @@ -8001,3 +8001,11 @@ f5(1) # E: Argument 1 to "f5" has incompatible type "int"; expected "Integral"
8001
8001
# N: Types from "numbers" aren't supported for static type checking \
8002
8002
# N: See https://peps.python.org/pep-0484/#the-numeric-tower \
8003
8003
# N: Consider using a protocol instead, such as typing.SupportsFloat
8004
+
8005
+ [case testImplicitClassScopedNames]
8006
+ class C:
8007
+ reveal_type(__module__) # N: Revealed type is "builtins.str"
8008
+ reveal_type(__qualname__) # N: Revealed type is "builtins.str"
8009
+ def f(self) -> None:
8010
+ __module__ # E: Name "__module__" is not defined
8011
+ __qualname__ # E: Name "__qualname__" is not defined
You can’t perform that action at this time.
0 commit comments