@@ -1321,15 +1321,18 @@ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> P
13211321 """
13221322
13231323 # We take the type from whichever of __init__ and __new__ is first
1324- # in the MRO, preferring __init__ if there is a tie.
1324+ # in the MRO, preferring __new__ if there is a tie.
13251325 init_method = info .get ("__init__" )
13261326 new_method = info .get ("__new__" )
13271327 if not init_method or not is_valid_constructor (init_method .node ):
13281328 # Must be an invalid class definition.
13291329 return AnyType (TypeOfAny .from_error )
13301330 # There *should* always be a __new__ method except the test stubs
13311331 # lack it, so just copy init_method in that situation
1332- new_method = new_method or init_method
1332+ if new_method is None :
1333+ new_method = named_type ("builtins.object" ).type .get ("__init__" )
1334+ if not new_method :
1335+ return AnyType (TypeOfAny .from_error )
13331336 if not is_valid_constructor (new_method .node ):
13341337 # Must be an invalid class definition.
13351338 return AnyType (TypeOfAny .from_error )
@@ -1363,12 +1366,13 @@ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> P
13631366 fallback = named_type ("builtins.function" ),
13641367 )
13651368 return class_callable (sig , info , fallback , None , is_new = False )
1366-
1367- # Otherwise prefer __init__ in a tie. It isn't clear that this
1368- # is the right thing, but __new__ caused problems with
1369- # typeshed (#5647).
1370- method = init_method .node
1371- is_new = False
1369+ if init_method .node .info .fullname == "builtins.dict" :
1370+ # dict.__new__ in typeshed is pretty unhelpful
1371+ method = init_method .node
1372+ is_new = False
1373+ else :
1374+ method = new_method .node
1375+ is_new = True
13721376 # Construct callable type based on signature of __init__. Adjust
13731377 # return type and insert type arguments.
13741378 if isinstance (method , FuncBase ):
0 commit comments