From 9e077c97a6b515ae3c6389567fa6dee4aaa8633b Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 17 Oct 2023 14:16:18 +0100 Subject: [PATCH 1/3] [WIP] Add failing test case --- test-data/unit/fine-grained.test | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index 68f72a2aa992..fe554b4550cd 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -10337,3 +10337,20 @@ b.py:1: note: Use "-> None" if function does not return a value == a.py:1: error: Function is missing a return type annotation a.py:1: note: Use "-> None" if function does not return a value + +[case testModuleLevelGetAttrInStub] +import stub +import a + +[file stub.pyi] +def __getattr__(self): pass + +[file a.py] + +[file a.py.2] +from stub import x +from stub.pkg import y +from stub.pkg.sub import z + +[out] +== From 32512675c8d9561a411e5821b30fd853e0094951 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 19 Oct 2023 13:35:13 -0700 Subject: [PATCH 2/3] Fix daemon false positive --- mypy/build.py | 10 ++++++---- test-data/unit/fine-grained.test | 12 +++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index b481cc6ad0dc..1385021aac48 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -1991,7 +1991,7 @@ def __init__( raise ModuleNotFound # Parse the file (and then some) to get the dependencies. - self.parse_file() + self.parse_file(temporary=temporary) self.compute_dependencies() @property @@ -2109,7 +2109,7 @@ def fix_cross_refs(self) -> None: # Methods for processing modules from source code. - def parse_file(self) -> None: + def parse_file(self, *, temporary: bool = False) -> None: """Parse file and run first pass of semantic analysis. Everything done here is local to the file. Don't depend on imported @@ -2194,12 +2194,14 @@ def parse_file(self) -> None: else: self.early_errors = manager.ast_cache[self.id][1] - modules[self.id] = self.tree + if not temporary: + modules[self.id] = self.tree if not cached: self.semantic_analysis_pass1() - self.check_blockers() + if not temporary: + self.check_blockers() manager.ast_cache[self.id] = (self.tree, self.early_errors) diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index fe554b4550cd..cb24467cbf41 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -10341,8 +10341,10 @@ a.py:1: note: Use "-> None" if function does not return a value [case testModuleLevelGetAttrInStub] import stub import a +import b -[file stub.pyi] +[file stub/__init__.pyi] +s: str def __getattr__(self): pass [file a.py] @@ -10352,5 +10354,13 @@ from stub import x from stub.pkg import y from stub.pkg.sub import z +[file b.py] + +[file b.py.3] +from stub import s +reveal_type(s) + [out] == +== +b.py:2: note: Revealed type is "builtins.str" From ce729121a2f20732d099ff0f84bae6d9b9d84592 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 19 Oct 2023 14:13:44 -0700 Subject: [PATCH 3/3] Update test case --- test-data/unit/fine-grained-modules.test | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test index 163e859276cb..f28dbaa1113b 100644 --- a/test-data/unit/fine-grained-modules.test +++ b/test-data/unit/fine-grained-modules.test @@ -837,15 +837,13 @@ p.a.f(1) [file p/__init__.py] [file p/a.py] def f(x: str) -> None: pass -[delete p/__init__.py.2] -[delete p/a.py.2] -def f(x: str) -> None: pass +[delete p.2] [out] main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" == main:1: error: Cannot find implementation or library stub for module named "p.a" main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports -main:2: error: "object" has no attribute "a" +main:1: error: Cannot find implementation or library stub for module named "p" [case testDeletePackage2] import p