Skip to content

Commit 425fb0b

Browse files
[1.0 backport] Adjust SCC setup to enable earlier collections.abc import in typeshed (#14531)
A backport of #14088 to the `release-1.0` branch. Co-authored-by: Michael Lee <[email protected]>
1 parent 0665ce9 commit 425fb0b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

mypy/semanal.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,12 @@ def refresh_top_level(self, file_node: MypyFile) -> None:
615615

616616
def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
617617
"""Manually add implicit definitions of module '__name__' etc."""
618+
str_type: Type | None = self.named_type_or_none("builtins.str")
619+
if str_type is None:
620+
str_type = UnboundType("builtins.str")
618621
for name, t in implicit_module_attrs.items():
619622
if name == "__doc__":
620-
typ: Type = UnboundType("__builtins__.str")
623+
typ: Type = str_type
621624
elif name == "__path__":
622625
if not file_node.is_package_init_file():
623626
continue
@@ -630,7 +633,7 @@ def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
630633
if not isinstance(node, TypeInfo):
631634
self.defer(node)
632635
return
633-
typ = Instance(node, [self.str_type()])
636+
typ = Instance(node, [str_type])
634637
elif name == "__annotations__":
635638
sym = self.lookup_qualified("__builtins__.dict", Context(), suppress_errors=True)
636639
if not sym:
@@ -639,7 +642,7 @@ def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
639642
if not isinstance(node, TypeInfo):
640643
self.defer(node)
641644
return
642-
typ = Instance(node, [self.str_type(), AnyType(TypeOfAny.special_form)])
645+
typ = Instance(node, [str_type, AnyType(TypeOfAny.special_form)])
643646
else:
644647
assert t is not None, f"type should be specified for {name}"
645648
typ = UnboundType(t)

mypy/semanal_main.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@
6666

6767
# Number of passes over core modules before going on to the rest of the builtin SCC.
6868
CORE_WARMUP: Final = 2
69-
core_modules: Final = ["typing", "builtins", "abc", "collections"]
69+
core_modules: Final = [
70+
"typing",
71+
"_collections_abc",
72+
"builtins",
73+
"abc",
74+
"collections",
75+
"collections.abc",
76+
]
7077

7178

7279
def semantic_analysis_for_scc(graph: Graph, scc: list[str], errors: Errors) -> None:

0 commit comments

Comments
 (0)