Skip to content

Commit 63b8f98

Browse files
pre-commit-ci[bot]Kunal Sali
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a0eb6ad commit 63b8f98

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

mypy/checker.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6252,17 +6252,30 @@ def conditional_callable_type_map(
62526252
proper_type = get_proper_type(current_type)
62536253
if isinstance(proper_type, AnyType):
62546254
# Narrow Any to a generic callable type to satisfy no-any-return in strict mode.
6255-
return {
6256-
expr: CallableType(
6257-
[AnyType(TypeOfAny.from_another_any, source_any=proper_type),
6258-
AnyType(TypeOfAny.from_another_any, source_any=proper_type)],
6259-
[nodes.ARG_STAR, nodes.ARG_STAR2],
6260-
[None, None],
6261-
ret_type=AnyType(TypeOfAny.from_another_any, source_any=proper_type),
6262-
fallback=self.named_type("builtins.function"),
6263-
is_ellipsis_args=True,
6264-
)
6265-
}, {}
6255+
# We use a synthesized fallback "<any callable fallback>" to preserve attribute
6256+
# access (fixing regressions in sympy, pandas, etc.) without triggering
6257+
# metaclass-related internal errors or breaking invariant subtyping.
6258+
obj_fallback = self.named_type("builtins.object")
6259+
if obj_fallback.type.fullname == "builtins.object":
6260+
cdef = nodes.ClassDef("<any callable fallback>", nodes.Block([]))
6261+
cdef._fullname = "<any callable fallback>"
6262+
info = TypeInfo(nodes.SymbolTable(), cdef, "")
6263+
info.mro = obj_fallback.type.mro
6264+
info.bases = obj_fallback.type.bases
6265+
info.fallback_to_any = True
6266+
fallback_instance = Instance(info, [])
6267+
6268+
return {
6269+
expr: CallableType(
6270+
[AnyType(TypeOfAny.from_another_any, source_any=proper_type),
6271+
AnyType(TypeOfAny.from_another_any, source_any=proper_type)],
6272+
[nodes.ARG_STAR, nodes.ARG_STAR2],
6273+
[None, None],
6274+
ret_type=AnyType(TypeOfAny.from_another_any, source_any=proper_type),
6275+
fallback=fallback_instance,
6276+
is_ellipsis_args=True,
6277+
)
6278+
}, {}
62666279

62676280
callables, uncallables = self.partition_by_callable(current_type, unsound_partition=False)
62686281

mypy/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3829,7 +3829,7 @@ def is_metaclass(self, *, precise: bool = False) -> bool:
38293829
return (
38303830
self.has_base("builtins.type")
38313831
or self.fullname == "abc.ABCMeta"
3832-
or (self.fallback_to_any and not precise)
3832+
or (self.fallback_to_any and not precise and self.fullname != "<any callable fallback>")
38333833
)
38343834

38353835
def has_base(self, fullname: str) -> bool:

0 commit comments

Comments
 (0)