diff --git a/mypy/build.py b/mypy/build.py index bd9fc43914db..6b0e4a9faa86 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -705,8 +705,8 @@ def __init__( self.quickstart_state = read_quickstart_file(options, self.stdout) # Fine grained targets (module top levels and top level functions) processed by # the semantic analyzer, used only for testing. Currently used only by the new - # semantic analyzer. - self.processed_targets: list[str] = [] + # semantic analyzer. Tuple of module and target name. + self.processed_targets: list[tuple[str, str]] = [] # Missing stub packages encountered. self.missing_stub_packages: set[str] = set() # Cache for mypy ASTs that have completed semantic analysis diff --git a/mypy/semanal_main.py b/mypy/semanal_main.py index a5e85878e931..912851520958 100644 --- a/mypy/semanal_main.py +++ b/mypy/semanal_main.py @@ -218,7 +218,7 @@ def process_top_levels(graph: Graph, scc: list[str], patches: Patches) -> None: state = graph[next_id] assert state.tree is not None deferred, incomplete, progress = semantic_analyze_target( - next_id, state, state.tree, None, final_iteration, patches + next_id, next_id, state, state.tree, None, final_iteration, patches ) all_deferred += deferred any_progress = any_progress or progress @@ -289,7 +289,7 @@ def process_top_level_function( # OK, this is one last pass, now missing names will be reported. analyzer.incomplete_namespaces.discard(module) deferred, incomplete, progress = semantic_analyze_target( - target, state, node, active_type, final_iteration, patches + target, module, state, node, active_type, final_iteration, patches ) if final_iteration: assert not deferred, "Must not defer during final iteration" @@ -318,6 +318,7 @@ def get_all_leaf_targets(file: MypyFile) -> list[TargetInfo]: def semantic_analyze_target( target: str, + module: str, state: State, node: MypyFile | FuncDef | OverloadedFuncDef | Decorator, active_type: TypeInfo | None, @@ -331,7 +332,7 @@ def semantic_analyze_target( - was some definition incomplete (need to run another pass) - were any new names defined (or placeholders replaced) """ - state.manager.processed_targets.append(target) + state.manager.processed_targets.append((module, target)) tree = state.tree assert tree is not None analyzer = state.manager.semantic_analyzer diff --git a/mypy/test/data.py b/mypy/test/data.py index 6e2ad198f614..3ee368869095 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -41,6 +41,14 @@ class DeleteFile(NamedTuple): FileOperation: _TypeAlias = Union[UpdateFile, DeleteFile] +def _file_arg_to_module(filename: str) -> str: + filename, _ = os.path.splitext(filename) + parts = filename.split("/") # not os.sep since it comes from test data + if parts[-1] == "__init__": + parts.pop() + return ".".join(parts) + + def parse_test_case(case: DataDrivenTestCase) -> None: """Parse and prepare a single case from suite with test case descriptions. @@ -65,22 +73,26 @@ def parse_test_case(case: DataDrivenTestCase) -> None: rechecked_modules: dict[int, set[str]] = {} # from run number module names triggered: list[str] = [] # Active triggers (one line per incremental step) targets: dict[int, list[str]] = {} # Fine-grained targets (per fine-grained update) + test_modules: list[str] = [] # Modules which are deemed "test" (vs "fixture") # Process the parsed items. Each item has a header of form [id args], # optionally followed by lines of text. item = first_item = test_items[0] + test_modules.append("__main__") for item in test_items[1:]: - if item.id in {"file", "outfile", "outfile-re"}: + if item.id in {"file", "fixture", "outfile", "outfile-re"}: # Record an extra file needed for the test case. assert item.arg is not None contents = expand_variables("\n".join(item.data)) - file_entry = (join(base_path, item.arg), contents) - if item.id == "file": - files.append(file_entry) + path = join(base_path, item.arg) + if item.id != "fixture": + test_modules.append(_file_arg_to_module(item.arg)) + if item.id in {"file", "fixture"}: + files.append((path, contents)) elif item.id == "outfile-re": - output_files.append((file_entry[0], re.compile(file_entry[1].rstrip(), re.S))) - else: - output_files.append(file_entry) + output_files.append((path, re.compile(contents.rstrip(), re.S))) + elif item.id == "outfile": + output_files.append((path, contents)) elif item.id == "builtins": # Use an alternative stub file for the builtins module. assert item.arg is not None @@ -207,6 +219,7 @@ def parse_test_case(case: DataDrivenTestCase) -> None: case.triggered = triggered or [] case.normalize_output = normalize_output case.expected_fine_grained_targets = targets + case.test_modules = test_modules class DataDrivenTestCase(pytest.Item): @@ -225,6 +238,8 @@ class DataDrivenTestCase(pytest.Item): # (file path, file content) tuples files: list[tuple[str, str]] + # Modules which is to be considered "test" rather than "fixture" + test_modules: list[str] expected_stale_modules: dict[int, set[str]] expected_rechecked_modules: dict[int, set[str]] expected_fine_grained_targets: dict[int, list[str]] diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index 4fe2ee6393c0..5f128283a190 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -11,7 +11,6 @@ from mypy.errors import CompileError from mypy.modulefinder import BuildSource, FindModuleCache, SearchPaths from mypy.options import TYPE_VAR_TUPLE, UNPACK -from mypy.semanal_main import core_modules from mypy.test.config import test_data_prefix, test_temp_dir from mypy.test.data import DataDrivenTestCase, DataSuite, FileOperation, module_from_path from mypy.test.helpers import ( @@ -188,12 +187,10 @@ def run_case_once( if incremental_step: name += str(incremental_step + 1) expected = testcase.expected_fine_grained_targets.get(incremental_step + 1) - actual = res.manager.processed_targets - # Skip the initial builtin cycle. actual = [ - t - for t in actual - if not any(t.startswith(mod) for mod in core_modules + ["mypy_extensions"]) + target + for module, target in res.manager.processed_targets + if module in testcase.test_modules ] if expected is not None: assert_target_equivalence(name, expected, actual) diff --git a/mypy/test/testdeps.py b/mypy/test/testdeps.py index 3343762cfaaf..faf4956a0273 100644 --- a/mypy/test/testdeps.py +++ b/mypy/test/testdeps.py @@ -41,16 +41,9 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: a = ["Unknown compile error (likely syntax error in test case or fixture)"] else: deps: defaultdict[str, set[str]] = defaultdict(set) - for module in files: - if ( - module in dumped_modules - or dump_all - and module - not in ("abc", "typing", "mypy_extensions", "typing_extensions", "enum") - ): - new_deps = get_dependencies( - files[module], type_map, options.python_version, options - ) + for module, file in files.items(): + if (module in dumped_modules or dump_all) and (module in testcase.test_modules): + new_deps = get_dependencies(file, type_map, options.python_version, options) for source in new_deps: deps[source].update(new_deps[source]) diff --git a/mypy/test/testmerge.py b/mypy/test/testmerge.py index 595aba49d8b7..11e9a3c3d7e7 100644 --- a/mypy/test/testmerge.py +++ b/mypy/test/testmerge.py @@ -36,18 +36,6 @@ AST = "AST" -NOT_DUMPED_MODULES = ( - "builtins", - "typing", - "abc", - "contextlib", - "sys", - "mypy_extensions", - "typing_extensions", - "enum", -) - - class ASTMergeSuite(DataSuite): files = ["merge.test"] @@ -84,13 +72,13 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: target_path = os.path.join(test_temp_dir, "target.py") shutil.copy(os.path.join(test_temp_dir, "target.py.next"), target_path) - a.extend(self.dump(fine_grained_manager, kind)) + a.extend(self.dump(fine_grained_manager, kind, testcase.test_modules)) old_subexpr = get_subexpressions(result.manager.modules["target"]) a.append("==>") new_file, new_types = self.build_increment(fine_grained_manager, "target", target_path) - a.extend(self.dump(fine_grained_manager, kind)) + a.extend(self.dump(fine_grained_manager, kind, testcase.test_modules)) for expr in old_subexpr: if isinstance(expr, TypeVarExpr): @@ -137,8 +125,12 @@ def build_increment( type_map = manager.graph[module_id].type_map() return module, type_map - def dump(self, manager: FineGrainedBuildManager, kind: str) -> list[str]: - modules = manager.manager.modules + def dump( + self, manager: FineGrainedBuildManager, kind: str, test_modules: list[str] + ) -> list[str]: + modules = { + name: file for name, file in manager.manager.modules.items() if name in test_modules + } if kind == AST: return self.dump_asts(modules) elif kind == TYPEINFO: @@ -146,15 +138,12 @@ def dump(self, manager: FineGrainedBuildManager, kind: str) -> list[str]: elif kind == SYMTABLE: return self.dump_symbol_tables(modules) elif kind == TYPES: - return self.dump_types(manager) + return self.dump_types(modules, manager) assert False, f"Invalid kind {kind}" def dump_asts(self, modules: dict[str, MypyFile]) -> list[str]: a = [] for m in sorted(modules): - if m in NOT_DUMPED_MODULES: - # We don't support incremental checking of changes to builtins, etc. - continue s = modules[m].accept(self.str_conv) a.extend(s.splitlines()) return a @@ -162,9 +151,6 @@ def dump_asts(self, modules: dict[str, MypyFile]) -> list[str]: def dump_symbol_tables(self, modules: dict[str, MypyFile]) -> list[str]: a = [] for id in sorted(modules): - if not is_dumped_module(id): - # We don't support incremental checking of changes to builtins, etc. - continue a.extend(self.dump_symbol_table(id, modules[id].names)) return a @@ -197,8 +183,6 @@ def format_symbol_table_node(self, node: SymbolTableNode) -> str: def dump_typeinfos(self, modules: dict[str, MypyFile]) -> list[str]: a = [] for id in sorted(modules): - if not is_dumped_module(id): - continue a.extend(self.dump_typeinfos_recursive(modules[id].names)) return a @@ -217,13 +201,13 @@ def dump_typeinfo(self, info: TypeInfo) -> list[str]: s = info.dump(str_conv=self.str_conv, type_str_conv=self.type_str_conv) return s.splitlines() - def dump_types(self, manager: FineGrainedBuildManager) -> list[str]: + def dump_types( + self, modules: dict[str, MypyFile], manager: FineGrainedBuildManager + ) -> list[str]: a = [] # To make the results repeatable, we try to generate unique and # deterministic sort keys. - for module_id in sorted(manager.manager.modules): - if not is_dumped_module(module_id): - continue + for module_id in sorted(modules): all_types = manager.manager.all_types # Compute a module type map from the global type map tree = manager.graph[module_id].tree @@ -242,7 +226,3 @@ def dump_types(self, manager: FineGrainedBuildManager) -> list[str]: def format_type(self, typ: Type) -> str: return typ.accept(self.type_str_conv) - - -def is_dumped_module(id: str) -> bool: - return id not in NOT_DUMPED_MODULES and (not id.startswith("_") or id == "__main__") diff --git a/mypy/test/testsemanal.py b/mypy/test/testsemanal.py index 71ebc43df8c2..3276f21540df 100644 --- a/mypy/test/testsemanal.py +++ b/mypy/test/testsemanal.py @@ -2,7 +2,6 @@ from __future__ import annotations -import os.path import sys from typing import Dict @@ -77,27 +76,9 @@ def test_semanal(testcase: DataDrivenTestCase) -> None: raise CompileError(a) # Include string representations of the source files in the actual # output. - for fnam in sorted(result.files.keys()): - f = result.files[fnam] - # Omit the builtins module and files with a special marker in the - # path. - # TODO the test is not reliable - if ( - not f.path.endswith( - ( - os.sep + "builtins.pyi", - "typing.pyi", - "mypy_extensions.pyi", - "typing_extensions.pyi", - "abc.pyi", - "collections.pyi", - "sys.pyi", - ) - ) - and not os.path.basename(f.path).startswith("_") - and not os.path.splitext(os.path.basename(f.path))[0].endswith("_") - ): - a += str(f).split("\n") + for module in sorted(result.files.keys()): + if module in testcase.test_modules: + a += str(result.files[module]).split("\n") except CompileError as e: a = e.messages if testcase.normalize_output: @@ -164,10 +145,10 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: a = result.errors if a: raise CompileError(a) - for f in sorted(result.files.keys()): - if f not in ("builtins", "typing", "abc"): - a.append(f"{f}:") - for s in str(result.files[f].names).split("\n"): + for module in sorted(result.files.keys()): + if module in testcase.test_modules: + a.append(f"{module}:") + for s in str(result.files[module].names).split("\n"): a.append(" " + s) except CompileError as e: a = e.messages @@ -199,11 +180,13 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: # Collect all TypeInfos in top-level modules. typeinfos = TypeInfoMap() - for f in result.files.values(): - for n in f.names.values(): - if isinstance(n.node, TypeInfo): - assert n.fullname - typeinfos[n.fullname] = n.node + for module, file in result.files.items(): + if module in testcase.test_modules: + for n in file.names.values(): + if isinstance(n.node, TypeInfo): + assert n.fullname + if any(n.fullname.startswith(m + ".") for m in testcase.test_modules): + typeinfos[n.fullname] = n.node # The output is the symbol table converted into a string. a = str(typeinfos).split("\n") @@ -220,12 +203,7 @@ class TypeInfoMap(Dict[str, TypeInfo]): def __str__(self) -> str: a: list[str] = ["TypeInfoMap("] for x, y in sorted(self.items()): - if ( - not x.startswith("builtins.") - and not x.startswith("typing.") - and not x.startswith("abc.") - ): - ti = ("\n" + " ").join(str(y).split("\n")) - a.append(f" {x} : {ti}") + ti = ("\n" + " ").join(str(y).split("\n")) + a.append(f" {x} : {ti}") a[-1] += ")" return "\n".join(a) diff --git a/mypy/test/testtransform.py b/mypy/test/testtransform.py index 1d3d4468444e..c765bae12062 100644 --- a/mypy/test/testtransform.py +++ b/mypy/test/testtransform.py @@ -2,8 +2,6 @@ from __future__ import annotations -import os.path - from mypy import build from mypy.errors import CompileError from mypy.modulefinder import BuildSource @@ -50,29 +48,12 @@ def test_transform(testcase: DataDrivenTestCase) -> None: raise CompileError(a) # Include string representations of the source files in the actual # output. - for fnam in sorted(result.files.keys()): - f = result.files[fnam] - - # Omit the builtins module and files with a special marker in the - # path. - # TODO the test is not reliable - if ( - not f.path.endswith( - ( - os.sep + "builtins.pyi", - "typing_extensions.pyi", - "typing.pyi", - "abc.pyi", - "sys.pyi", - ) - ) - and not os.path.basename(f.path).startswith("_") - and not os.path.splitext(os.path.basename(f.path))[0].endswith("_") - ): + for module in sorted(result.files.keys()): + if module in testcase.test_modules: t = TypeAssertTransformVisitor() t.test_only = True - f = t.mypyfile(f) - a += str(f).split("\n") + file = t.mypyfile(result.files[module]) + a += str(file).split("\n") except CompileError as e: a = e.messages if testcase.normalize_output: diff --git a/mypy/test/testtypegen.py b/mypy/test/testtypegen.py index 22ef4272e933..3f09254f081a 100644 --- a/mypy/test/testtypegen.py +++ b/mypy/test/testtypegen.py @@ -48,6 +48,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: # to simplify output. searcher = SkippedNodeSearcher() for file in result.files.values(): + searcher.ignore_file = file.fullname not in testcase.test_modules file.accept(searcher) ignored = searcher.nodes diff --git a/mypy/test/visitors.py b/mypy/test/visitors.py index 771119dbdc70..2b748ec1bdc4 100644 --- a/mypy/test/visitors.py +++ b/mypy/test/visitors.py @@ -8,15 +8,7 @@ from __future__ import annotations -from mypy.nodes import ( - AssignmentStmt, - CallExpr, - Expression, - IntExpr, - MypyFile, - NameExpr, - TypeVarExpr, -) +from mypy.nodes import AssignmentStmt, CallExpr, Expression, IntExpr, NameExpr, Node, TypeVarExpr from mypy.traverser import TraverserVisitor from mypy.treetransform import TransformVisitor from mypy.types import Type @@ -25,12 +17,8 @@ # from testtypegen class SkippedNodeSearcher(TraverserVisitor): def __init__(self) -> None: - self.nodes: set[Expression] = set() - self.is_typing = False - - def visit_mypy_file(self, f: MypyFile) -> None: - self.is_typing = f.fullname == "typing" or f.fullname == "builtins" - super().visit_mypy_file(f) + self.nodes: set[Node] = set() + self.ignore_file = False def visit_assignment_stmt(self, s: AssignmentStmt) -> None: if s.type or ignore_node(s.rvalue): @@ -40,14 +28,14 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None: super().visit_assignment_stmt(s) def visit_name_expr(self, n: NameExpr) -> None: - self.skip_if_typing(n) + if self.ignore_file: + self.nodes.add(n) + super().visit_name_expr(n) def visit_int_expr(self, n: IntExpr) -> None: - self.skip_if_typing(n) - - def skip_if_typing(self, n: Expression) -> None: - if self.is_typing: + if self.ignore_file: self.nodes.add(n) + super().visit_int_expr(n) def ignore_node(node: Expression) -> bool: diff --git a/test-data/unit/README.md b/test-data/unit/README.md index 6cf0b1bb26cf..97680c949bef 100644 --- a/test-data/unit/README.md +++ b/test-data/unit/README.md @@ -36,7 +36,7 @@ the error message - `W: ...` and `N: ...` works exactly like `E: ...`, but report a warning and a note respectively - lines that don't contain the above should cause no type check errors - optional `[builtins fixtures/...]` tells the type checker to use -stubs from the indicated file (see Fixtures section below) +`builtins` stubs from the indicated file (see Fixtures section below) - optional `[out]` is an alternative to the `# E: ` notation: it indicates that any text after it contains the expected type checking error messages. Usually, `# E: ` is preferred because it makes it easier to associate the @@ -65,7 +65,7 @@ Where the stubs for builtins come from for a given test: - The builtins used by default in unit tests live in `test-data/unit/lib-stub`. -- Individual test cases can override the builtins stubs by using +- Individual test cases can override the `builtins` stubs by using `[builtins fixtures/foo.pyi]`; this targets files in `test-data/unit/fixtures`. Feel free to modify existing files there or create new ones as you deem fit. @@ -77,6 +77,21 @@ Where the stubs for builtins come from for a given test: addition with other mypy developers, as additions could slow down the test suite. +- Some tests choose to customize the standard library in a way that's local to the test: + ``` + [case testFoo] + ... + [file builtins.py] + class int: + def next_fibonacci() -> int: pass + ``` + Another possible syntax is: + ``` + [fixture builtins.py] + ``` + Whether you use `[file ...]` or `[fixture ...]` depends on whether you want + the file to be part of the tested corpus (e.g. contribute to `[out]` section) + or only support the test. Running tests and linting ------------------------- diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index e3d6188b643b..970dc05b488d 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -9,7 +9,7 @@ reveal_type(p) # N: Revealed type is "TypedDict('__main__.Point', {'x': builtin reveal_type(p.values()) # N: Revealed type is "typing.Iterable[builtins.object]" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] -[targets sys, __main__] +[targets __main__] [case testCanCreateTypedDictInstanceWithDictCall] from mypy_extensions import TypedDict diff --git a/test-data/unit/deps-types.test b/test-data/unit/deps-types.test index 1d7064cde0c7..def117fe04df 100644 --- a/test-data/unit/deps-types.test +++ b/test-data/unit/deps-types.test @@ -852,8 +852,6 @@ class I: pass -> a -> , a, mod.I -> a - -> sys - -> sys [case testAliasDepsClassInFunction] from mod import I diff --git a/test-data/unit/merge.test b/test-data/unit/merge.test index 144a095440f2..42d38c89482c 100644 --- a/test-data/unit/merge.test +++ b/test-data/unit/merge.test @@ -1086,7 +1086,7 @@ a: A [file target.py.next] from _x import A a: A -[file _x.pyi] +[fixture _x.pyi] from typing import Generic, TypeVar, overload T = TypeVar('T') diff --git a/test-data/unit/semanal-modules.test b/test-data/unit/semanal-modules.test index bc381293161f..116747ae5cb9 100644 --- a/test-data/unit/semanal-modules.test +++ b/test-data/unit/semanal-modules.test @@ -77,9 +77,9 @@ MypyFile:1( [case testImportMultiple] import _m, _n _m.x, _n.y -[file _m.py] +[fixture _m.py] x = 1 -[file _n.py] +[fixture _n.py] y = 2 [out] MypyFile:1( @@ -96,7 +96,7 @@ MypyFile:1( [case testImportAs] import _m as n n.x -[file _m.py] +[fixture _m.py] x = 1 [out] MypyFile:1( @@ -109,7 +109,7 @@ MypyFile:1( [case testImportFromMultiple] from _m import x, y x, y -[file _m.py] +[fixture _m.py] x = y = 1 [out] MypyFile:1( @@ -122,7 +122,7 @@ MypyFile:1( [case testImportFromAs] from _m import y as z z -[file _m.py] +[fixture _m.py] y = 1 [out] MypyFile:1( @@ -135,7 +135,7 @@ from m import x y = x [file m.py] from _n import x -[file _n.py] +[fixture _n.py] x = 1 [out] MypyFile:1( @@ -150,9 +150,9 @@ MypyFile:1( [case testAccessImportedName2] import _m y = _m.x -[file _m.py] +[fixture _m.py] from _n import x -[file _n.py] +[fixture _n.py] x = 1 [out] MypyFile:1( @@ -166,9 +166,9 @@ MypyFile:1( [case testAccessingImportedNameInType] from _m import c x = None # type: c -[file _m.py] +[fixture _m.py] from _n import c -[file _n.py] +[fixture _n.py] class c: pass [out] MypyFile:1( @@ -181,9 +181,9 @@ MypyFile:1( [case testAccessingImportedNameInType2] import _m x = None # type: _m.c -[file _m.py] +[fixture _m.py] from _n import c -[file _n.py] +[fixture _n.py] class c: pass [out] MypyFile:1( @@ -196,9 +196,9 @@ MypyFile:1( [case testAccessingImportedModule] from _m import _n _n.x -[file _m.py] +[fixture _m.py] import _n -[file _n.py] +[fixture _n.py] x = 1 [out] MypyFile:1( @@ -211,9 +211,9 @@ MypyFile:1( [case testAccessingImportedModule2] import _m _m._n.x -[file _m.py] +[fixture _m.py] import _n -[file _n.py] +[fixture _n.py] x = 1 [out] MypyFile:1( @@ -228,9 +228,9 @@ MypyFile:1( [case testAccessTypeViaDoubleIndirection] from _m import c a = None # type: c -[file _m.py] +[fixture _m.py] from _n import c -[file _n.py] +[fixture _n.py] class c: pass [out] MypyFile:1( @@ -243,9 +243,9 @@ MypyFile:1( [case testAccessTypeViaDoubleIndirection2] import _m a = None # type: _m.c -[file _m.py] +[fixture _m.py] from _n import c -[file _n.py] +[fixture _n.py] class c: pass [out] MypyFile:1( @@ -258,7 +258,7 @@ MypyFile:1( [case testImportAsterisk] from _m import * x, y -[file _m.py] +[fixture _m.py] x = y = 1 [out] MypyFile:1( @@ -271,10 +271,10 @@ MypyFile:1( [case testImportAsteriskAndImportedNames] from _m import * n_.x, y -[file _m.py] +[fixture _m.py] import n_ from n_ import y -[file n_.py] +[fixture n_.py] x = y = 1 [out] MypyFile:1( @@ -290,10 +290,10 @@ MypyFile:1( from _m import * x = None # type: n_.c y = None # type: d -[file _m.py] +[fixture _m.py] import n_ from n_ import d -[file n_.py] +[fixture n_.py] class c: pass class d: pass [out] @@ -311,7 +311,7 @@ MypyFile:1( [case testModuleInSubdir] import _m _m.x -[file _m/__init__.py] +[fixture _m/__init__.py] x = 1 [out] MypyFile:1( @@ -324,7 +324,7 @@ MypyFile:1( [case testNestedModules] import m.n m.n.x, m.y -[file m/__init__.py] +[fixture m/__init__.py] y = 1 [file m/n.py] x = 1 @@ -351,8 +351,8 @@ MypyFile:1( [case testImportFromSubmodule] from m._n import x x -[file m/__init__.py] -[file m/_n.py] +[fixture m/__init__.py] +[fixture m/_n.py] x = 1 [out] MypyFile:1( @@ -363,8 +363,8 @@ MypyFile:1( [case testImportAllFromSubmodule] from m._n import * x, y -[file m/__init__.py] -[file m/_n.py] +[fixture m/__init__.py] +[fixture m/_n.py] x = y = 1 [out] MypyFile:1( @@ -377,8 +377,8 @@ MypyFile:1( [case testSubmodulesAndTypes] import m._n x = None # type: m._n.c -[file m/__init__.py] -[file m/_n.py] +[fixture m/__init__.py] +[fixture m/_n.py] class c: pass [out] MypyFile:1( @@ -391,8 +391,8 @@ MypyFile:1( [case testSubmodulesAndTypes2] from m._n import c x = None # type: c -[file m/__init__.py] -[file m/_n.py] +[fixture m/__init__.py] +[fixture m/_n.py] class c: pass [out] MypyFile:1( @@ -405,8 +405,8 @@ MypyFile:1( [case testFromPackageImportModule] from m import _n _n.x -[file m/__init__.py] -[file m/_n.py] +[fixture m/__init__.py] +[fixture m/_n.py] x = 1 [out] MypyFile:1( @@ -421,9 +421,9 @@ import m.n.k m.n.k.x m.n.b m.a -[file m/__init__.py] +[fixture m/__init__.py] a = 1 -[file m/n/__init__.py] +[fixture m/n/__init__.py] b = 1 [file m/n/k.py] x = 1 @@ -458,10 +458,10 @@ MypyFile:1( [case testImportInSubmodule] import m._n y = m._n.x -[file m/__init__.py] -[file m/_n.py] +[fixture m/__init__.py] +[fixture m/_n.py] from m._k import x -[file m/_k.py] +[fixture m/_k.py] x = 1 [out] MypyFile:1( @@ -494,7 +494,7 @@ MypyFile:1( import _m _m.x = ( _m.x) -[file _m.py] +[fixture _m.py] x = None [out] MypyFile:1( @@ -510,7 +510,7 @@ MypyFile:1( [case testAssignmentThatRefersToModule] import _m _m.x[None] = None -[file _m.py] +[fixture _m.py] x = None [out] MypyFile:1( @@ -527,7 +527,7 @@ MypyFile:1( if 1: import _x _x.y -[file _x.py] +[fixture _x.py] y = 1 [out] MypyFile:1( @@ -545,7 +545,7 @@ MypyFile:1( def f() -> None: import _x _x.y -[file _x.py] +[fixture _x.py] y = 1 [out] MypyFile:1( @@ -563,7 +563,7 @@ MypyFile:1( class A: from _x import y z = y -[file _x.py] +[fixture _x.py] y = 1 [out] MypyFile:1( @@ -578,7 +578,7 @@ MypyFile:1( class A: import _x z = _x.y -[file _x.py] +[fixture _x.py] y = 1 [out] MypyFile:1( @@ -620,7 +620,7 @@ MypyFile:1( [case testRelativeImport0] import m.x m.x.z.y -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] from . import z [file m/z.py] @@ -650,12 +650,12 @@ MypyFile:1( import m.t.b as b b.x.y b.z.y -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] y = 1 [file m/z.py] y = 3 -[file m/t/__init__.py] +[fixture m/t/__init__.py] [file m/t/b.py] from .. import x, z [out] @@ -693,12 +693,12 @@ MypyFile:1( import m.t.b as b b.xy b.zy -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] y = 1 [file m/z.py] y = 3 -[file m/t/__init__.py] +[fixture m/t/__init__.py] [file m/t/b.py] from ..x import y as xy from ..z import y as zy @@ -735,14 +735,14 @@ import m.t m.zy m.xy m.t.y -[file m/__init__.py] +[fixture m/__init__.py] from .x import * from .z import * [file m/x.py] from .z import zy as xy [file m/z.py] zy = 3 -[file m/t/__init__.py] +[fixture m/t/__init__.py] from .b import * [file m/t/b.py] from .. import xy as y @@ -778,7 +778,7 @@ MypyFile:1( [case testRelativeImportFromSameModule] import m.x -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] from .x import nonexistent [out] @@ -786,7 +786,7 @@ tmp/m/x.py:1: error: Module "m.x" has no attribute "nonexistent" [case testImportFromSameModule] import m.x -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] from m.x import nonexistent [out] @@ -794,7 +794,7 @@ tmp/m/x.py:1: error: Module "m.x" has no attribute "nonexistent" [case testImportMisspellingSingleCandidate] import f -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] def some_function(): pass @@ -805,7 +805,7 @@ tmp/f.py:1: error: Module "m.x" has no attribute "somefunction"; maybe "some_fun [case testImportMisspellingMultipleCandidates] import f -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] def some_function(): pass @@ -818,7 +818,7 @@ tmp/f.py:1: error: Module "m.x" has no attribute "somefunction"; maybe "some_fun [case testImportMisspellingMultipleCandidatesTruncated] import f -[file m/__init__.py] +[fixture m/__init__.py] [file m/x.py] def some_function(): pass @@ -849,10 +849,10 @@ y = 2 from m_ import * x y -[file m_.py] +[fixture m_.py] from m2_ import x as x from m2_ import y -[file m2_.py] +[fixture m2_.py] x = 1 y = 2 [out] @@ -878,11 +878,11 @@ import m3 from m_ import * m2_ m3_ -[file m_.py] +[fixture m_.py] import m2_ as m2_ import m3_ -[file m2_.py] -[file m3_.py] +[fixture m2_.py] +[fixture m3_.py] [out] MypyFile:1( ImportAll:1(m_) diff --git a/test-data/unit/semanal-python310.test b/test-data/unit/semanal-python310.test index 9418ac2912b2..e96a3ca9d777 100644 --- a/test-data/unit/semanal-python310.test +++ b/test-data/unit/semanal-python310.test @@ -194,7 +194,7 @@ x = 1 match x: case _a.b: pass -[file _a.py] +[fixture _a.py] b = 1 [out] MypyFile:1( diff --git a/test-data/unit/semanal-symtable.test b/test-data/unit/semanal-symtable.test index c886080557b0..1622fd1f1ad4 100644 --- a/test-data/unit/semanal-symtable.test +++ b/test-data/unit/semanal-symtable.test @@ -78,10 +78,6 @@ __main__: non_existing2 : Gdef/Var (__main__.non_existing2) : Any non_existing3 : Gdef/Var (__main__.non_existing3) : Any non_existing4 : Gdef/Var (__main__.non_existing4) : Any) -sys: - SymbolTable( - platform : Gdef/Var (sys.platform) : builtins.str - version_info : Gdef/Var (sys.version_info)) [case testDecorator] from typing import Callable diff --git a/test-data/unit/semanal-typealiases.test b/test-data/unit/semanal-typealiases.test index debc7ecdf722..88d234134350 100644 --- a/test-data/unit/semanal-typealiases.test +++ b/test-data/unit/semanal-typealiases.test @@ -92,7 +92,7 @@ import typing import _m A2 = _m.A x = 1 # type: A2 -[file _m.py] +[fixture _m.py] import typing class A: pass [out] @@ -255,7 +255,7 @@ MypyFile:1( import typing from _m import U def f(x: U) -> None: pass -[file _m.py] +[fixture _m.py] from typing import Union class A: pass U = Union[int, A] @@ -275,7 +275,7 @@ MypyFile:1( import typing import _m def f(x: _m.U) -> None: pass -[file _m.py] +[fixture _m.py] from typing import Union class A: pass U = Union[int, A] @@ -295,7 +295,7 @@ MypyFile:1( import typing from _m import A def f(x: A) -> None: pass -[file _m.py] +[fixture _m.py] import typing A = int [out] @@ -314,7 +314,7 @@ MypyFile:1( import typing import _m def f(x: _m.A) -> None: pass -[file _m.py] +[fixture _m.py] import typing A = int [out] @@ -385,7 +385,7 @@ from typing import Union from _m import U U2 = U x = 1 # type: U2 -[file _m.py] +[fixture _m.py] from typing import Union U = Union[int, str] [out] diff --git a/test-data/unit/semanal-types.test b/test-data/unit/semanal-types.test index 494d701b758a..05fc08d8a49e 100644 --- a/test-data/unit/semanal-types.test +++ b/test-data/unit/semanal-types.test @@ -303,7 +303,7 @@ MypyFile:1( import typing import _m typing.cast(_m.C, object) -[file _m.py] +[fixture _m.py] class C: pass [out] MypyFile:1( @@ -318,8 +318,8 @@ MypyFile:1( import typing import _m._n typing.cast(_m._n.C, object) -[file _m/__init__.py] -[file _m/_n.py] +[fixture _m/__init__.py] +[fixture _m/_n.py] class C: pass [out] MypyFile:1( @@ -1152,7 +1152,7 @@ from typing import Generic from _m import T class A(Generic[T]): y = None # type: T -[file _m.py] +[fixture _m.py] from typing import TypeVar T = TypeVar('T') [out] @@ -1175,7 +1175,7 @@ class A(Generic[_m.T]): a = None # type: _m.T def f(self, x: _m.T): b = None # type: _m.T -[file _m.py] +[fixture _m.py] from typing import TypeVar T = TypeVar('T') [out] @@ -1206,7 +1206,7 @@ MypyFile:1( import _m def f(x: _m.T) -> None: a = None # type: _m.T -[file _m.py] +[fixture _m.py] from typing import TypeVar T = TypeVar('T') [out]