Make free type variables generic in the type if possible. This will translate the type `tp` while trying to create valid bindings for type variables `poly_tvars` while traversing the type. This follows the same rules as we do during semantic analysis phase, examples: * Callable[Ca
(tp: CallableType, poly_tvars: Sequence[TypeVarLikeType])
| 180 | |
| 181 | |
| 182 | def apply_poly(tp: CallableType, poly_tvars: Sequence[TypeVarLikeType]) -> CallableType | None: |
| 183 | """Make free type variables generic in the type if possible. |
| 184 | |
| 185 | This will translate the type `tp` while trying to create valid bindings for |
| 186 | type variables `poly_tvars` while traversing the type. This follows the same rules |
| 187 | as we do during semantic analysis phase, examples: |
| 188 | * Callable[Callable[[T], T], T] -> def [T] (def (T) -> T) -> T |
| 189 | * Callable[[], Callable[[T], T]] -> def () -> def [T] (T -> T) |
| 190 | * List[T] -> None (not possible) |
| 191 | """ |
| 192 | try: |
| 193 | return tp.copy_modified( |
| 194 | arg_types=[t.accept(PolyTranslator(poly_tvars)) for t in tp.arg_types], |
| 195 | ret_type=tp.ret_type.accept(PolyTranslator(poly_tvars)), |
| 196 | variables=[], |
| 197 | ) |
| 198 | except PolyTranslationError: |
| 199 | return None |
| 200 | |
| 201 | |
| 202 | class PolyTranslationError(Exception): |
nothing calls this directly
no test coverage detected
searching dependent graphs…