|
29 | 29 | Instance,
|
30 | 30 | Overloaded,
|
31 | 31 | ProperType,
|
| 32 | + TupleType, |
32 | 33 | TypeOfAny,
|
33 | 34 | TypeType,
|
34 | 35 | TypeVarType,
|
@@ -250,15 +251,25 @@ def _replace_type_var(ret_type: MypyType, to_replace: str, replace_by: MypyType)
|
250 | 251 |
|
251 | 252 | if isinstance(ret_type, Instance):
|
252 | 253 | # Since it is an instance, recursively find the type var for all its args.
|
253 |
| - ret_type.args = tuple(_replace_type_var(item, to_replace, replace_by) for item in ret_type.args) |
254 |
| - return ret_type |
255 |
| - |
256 |
| - if hasattr(ret_type, "item"): |
257 |
| - # For example TypeType has an item. find the type_var for this item |
258 |
| - ret_type.item = _replace_type_var(ret_type.item, to_replace, replace_by) |
259 |
| - if hasattr(ret_type, "items"): |
260 |
| - # For example TypeList has items. find recursively type_var for its items |
261 |
| - ret_type.items = [_replace_type_var(item, to_replace, replace_by) for item in ret_type.items] |
| 254 | + return ret_type.copy_modified( |
| 255 | + args=tuple(_replace_type_var(item, to_replace, replace_by) for item in ret_type.args) |
| 256 | + ) |
| 257 | + elif isinstance(ret_type, TypeType): |
| 258 | + return TypeType.make_normalized( |
| 259 | + _replace_type_var(ret_type.item, to_replace, replace_by), |
| 260 | + line=ret_type.line, |
| 261 | + column=ret_type.column, |
| 262 | + ) |
| 263 | + elif isinstance(ret_type, TupleType): |
| 264 | + return ret_type.copy_modified( |
| 265 | + items=[_replace_type_var(item, to_replace, replace_by) for item in ret_type.items] |
| 266 | + ) |
| 267 | + elif isinstance(ret_type, UnionType): |
| 268 | + return UnionType.make_union( |
| 269 | + items=[_replace_type_var(item, to_replace, replace_by) for item in ret_type.items], |
| 270 | + line=ret_type.line, |
| 271 | + column=ret_type.column, |
| 272 | + ) |
262 | 273 | return ret_type
|
263 | 274 |
|
264 | 275 |
|
|
0 commit comments