Skip to content

Commit 8610329

Browse files
authored
Don't use ModuleType.__getattr__ if we know module symbols (#11597)
python/typeshd#6302 added `__getattr__`, but we don't want to always use it, as it can result in undefined references to module attributes being undetected. This is an alternative to python/typeshed#6357. Tested manually with a recent typeshed.
1 parent bc5b919 commit 8610329

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mypy/checkmember.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ def analyze_member_var_access(name: str,
381381
elif isinstance(v, FuncDef):
382382
assert False, "Did not expect a function"
383383
elif (not v and name not in ['__getattr__', '__setattr__', '__getattribute__'] and
384-
not mx.is_operator):
384+
not mx.is_operator and mx.module_symbol_table is None):
385+
# Above we skip ModuleType.__getattr__ etc. if we have a
386+
# module symbol table, since the symbol table allows precise
387+
# checking.
385388
if not mx.is_lvalue:
386389
for method_name in ('__getattribute__', '__getattr__'):
387390
method = info.get_method(method_name)

0 commit comments

Comments
 (0)