@@ -414,57 +414,15 @@ def class_callable(init_type: CallableType, info: TypeInfo, type_type: Instance,
414
414
special_sig : Optional [str ]) -> CallableType :
415
415
"""Create a type object type based on the signature of __init__."""
416
416
variables = [] # type: List[TypeVarDef]
417
- for i , tvar in enumerate (info .defn .type_vars ):
418
- variables .append (TypeVarDef (tvar .name , i + 1 , tvar .values , tvar .upper_bound ,
419
- tvar .variance ))
420
-
421
- class_variables = variables
422
- initvars = init_type .variables
423
- variables .extend (initvars )
417
+ variables .extend (info .defn .type_vars )
418
+ variables .extend (init_type .variables )
424
419
425
420
callable_type = init_type .copy_modified (
426
421
ret_type = self_type (info ), fallback = type_type , name = None , variables = variables ,
427
422
special_sig = special_sig )
428
423
c = callable_type .with_name ('"{}"' .format (info .name ()))
429
- cc = convert_class_tvars_to_func_tvars (c , class_variables , len (initvars ))
430
- cc .is_classmethod_class = True
431
- return cc
432
-
433
-
434
- def convert_class_tvars_to_func_tvars (callable : CallableType ,
435
- class_variables : List [TypeVarDef ],
436
- num_func_tvars : int ) -> CallableType :
437
- tvar_def_translation = {} # type: Dict[TypeVarId, TypeVarDef]
438
- for v in class_variables :
439
- tvar_def_translation [v .id ] = \
440
- TypeVarDef (v .name , - v .id .raw_id - num_func_tvars ,
441
- v .values , v .upper_bound , v .variance )
442
-
443
- return cast (CallableType , callable .accept (TvarTranslator (tvar_def_translation )))
444
-
445
-
446
- class TvarTranslator (TypeTranslator ):
447
- def __init__ (self , translation : Dict [TypeVarId , TypeVarDef ]) -> None :
448
- super ().__init__ ()
449
- self .translation = translation
450
-
451
- def visit_type_var (self , t : TypeVarType ) -> Type :
452
- if t .id in self .translation :
453
- return TypeVarType (self .translation [t .id ])
454
- else :
455
- return t
456
-
457
- def translate_variables (self ,
458
- variables : List [TypeVarDef ]) -> List [TypeVarDef ]:
459
- if not variables :
460
- return variables
461
- items = [] # type: List[TypeVarDef]
462
- for v in variables :
463
- if v .id in self .translation :
464
- items .append (self .translation [v .id ])
465
- else :
466
- items .append (v )
467
- return items
424
+ c .is_classmethod_class = True
425
+ return c
468
426
469
427
470
428
def map_type_from_supertype (typ : Type , sub_info : TypeInfo ,
0 commit comments