@@ -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
0 commit comments