Esempio n. 1
0
 def replace_alias_tvars(self, tp: Type, vars: List[str], subs: List[Type],
                         newline: int, newcolumn: int) -> Type:
     """Replace type variables in a generic type alias tp with substitutions subs
     resetting context. Length of subs should be already checked.
     """
     typ_args = get_typ_args(tp)
     new_args = typ_args[:]
     for i, arg in enumerate(typ_args):
         tvar = self.get_tvar_name(arg)
         if tvar and tvar in vars:
             # Perform actual substitution...
             new_args[i] = subs[vars.index(tvar)]
         else:
             # ...recursively, if needed.
             new_args[i] = self.replace_alias_tvars(arg, vars, subs, newline, newcolumn)
     return set_typ_args(tp, new_args, newline, newcolumn)
 def replace_alias_tvars(self, tp: Type, vars: List[str], subs: List[Type],
                         newline: int, newcolumn: int) -> Type:
     """Replace type variables in a generic type alias tp with substitutions subs
     resetting context. Length of subs should be already checked.
     """
     typ_args = get_typ_args(tp)
     new_args = typ_args[:]
     for i, arg in enumerate(typ_args):
         tvar = self.get_tvar_name(arg)
         if tvar and tvar in vars:
             # Perform actual substitution...
             new_args[i] = subs[vars.index(tvar)]
         else:
             # ...recursively, if needed.
             new_args[i] = self.replace_alias_tvars(arg, vars, subs, newline, newcolumn)
     return set_typ_args(tp, new_args, newline, newcolumn)
Esempio n. 3
0
 def get_type_var_names(self, tp: Type) -> List[str]:
     """Get all type variable names that are present in a generic type alias
     in order of textual appearance (recursively, if needed).
     """
     tvars = []  # type: List[str]
     typ_args = get_typ_args(tp)
     for arg in typ_args:
         tvar = self.get_tvar_name(arg)
         if tvar:
             tvars.append(tvar)
         else:
             subvars = self.get_type_var_names(arg)
             if subvars:
                 tvars.extend(subvars)
     # Get unique type variables in order of appearance
     all_tvars = set(tvars)
     new_tvars = []
     for t in tvars:
         if t in all_tvars:
             new_tvars.append(t)
             all_tvars.remove(t)
     return new_tvars
Esempio n. 4
0
 def get_type_var_names(self, tp: Type) -> List[str]:
     """Get all type variable names that are present in a generic type alias
     in order of textual appearance (recursively, if needed).
     """
     tvars = []  # type: List[str]
     typ_args = get_typ_args(tp)
     for arg in typ_args:
         tvar = self.get_tvar_name(arg)
         if tvar:
             tvars.append(tvar)
         else:
             subvars = self.get_type_var_names(arg)
             if subvars:
                 tvars.extend(subvars)
     # Get unique type variables in order of appearance
     all_tvars = set(tvars)
     new_tvars = []
     for t in tvars:
         if t in all_tvars:
             new_tvars.append(t)
             all_tvars.remove(t)
     return new_tvars