Skip to content

Adjust SCC setup to enable earlier collections.abc import in typeshed #14088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,12 @@ def refresh_top_level(self, file_node: MypyFile) -> None:

def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
"""Manually add implicit definitions of module '__name__' etc."""
str_type: Type | None = self.named_type_or_none("builtins.str")
if str_type is None:
str_type = UnboundType("builtins.str")
for name, t in implicit_module_attrs.items():
if name == "__doc__":
typ: Type = UnboundType("__builtins__.str")
typ: Type = str_type
elif name == "__path__":
if not file_node.is_package_init_file():
continue
Expand All @@ -612,7 +615,7 @@ def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
if not isinstance(node, TypeInfo):
self.defer(node)
return
typ = Instance(node, [self.str_type()])
typ = Instance(node, [str_type])
elif name == "__annotations__":
sym = self.lookup_qualified("__builtins__.dict", Context(), suppress_errors=True)
if not sym:
Expand All @@ -621,7 +624,7 @@ def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
if not isinstance(node, TypeInfo):
self.defer(node)
return
typ = Instance(node, [self.str_type(), AnyType(TypeOfAny.special_form)])
typ = Instance(node, [str_type, AnyType(TypeOfAny.special_form)])
else:
assert t is not None, f"type should be specified for {name}"
typ = UnboundType(t)
Expand Down
9 changes: 8 additions & 1 deletion mypy/semanal_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@

# Number of passes over core modules before going on to the rest of the builtin SCC.
CORE_WARMUP: Final = 2
core_modules: Final = ["typing", "builtins", "abc", "collections"]
core_modules: Final = [
"typing",
"_collections_abc",
"builtins",
"abc",
"collections",
"collections.abc",
]


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