From ab1ab32953c0f430a44e20d4dcfd8905995e4d51 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 23 Nov 2021 10:10:32 +0000 Subject: [PATCH] Don't use ModuleType.__getattr__ if we know module symbols 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. --- mypy/checkmember.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mypy/checkmember.py b/mypy/checkmember.py index 01c6afeb9cec..e42c7ad50a6f 100644 --- a/mypy/checkmember.py +++ b/mypy/checkmember.py @@ -381,7 +381,10 @@ def analyze_member_var_access(name: str, elif isinstance(v, FuncDef): assert False, "Did not expect a function" elif (not v and name not in ['__getattr__', '__setattr__', '__getattribute__'] and - not mx.is_operator): + not mx.is_operator and mx.module_symbol_table is None): + # Above we skip ModuleType.__getattr__ etc. if we have a + # module symbol table, since the symbol table allows precise + # checking. if not mx.is_lvalue: for method_name in ('__getattribute__', '__getattr__'): method = info.get_method(method_name)