|
6 | 6 |
|
7 | 7 | from mypy import errorcodes as codes, message_registry
|
8 | 8 | from mypy.errorcodes import ErrorCode
|
| 9 | +from mypy.expandtype import expand_type |
9 | 10 | from mypy.exprtotype import TypeTranslationError, expr_to_unanalyzed_type
|
10 | 11 | from mypy.messages import MessageBuilder
|
11 | 12 | from mypy.nodes import (
|
|
45 | 46 | TypedDictType,
|
46 | 47 | TypeOfAny,
|
47 | 48 | TypeVarLikeType,
|
48 |
| - replace_alias_tvars, |
49 | 49 | )
|
50 | 50 |
|
51 | 51 | TPDICT_CLASS_ERROR: Final = (
|
@@ -243,21 +243,18 @@ def map_items_to_base(
|
243 | 243 | ) -> dict[str, Type]:
|
244 | 244 | """Map item types to how they would look in their base with type arguments applied.
|
245 | 245 |
|
246 |
| - We would normally use expand_type() for such task, but we can't use it during |
247 |
| - semantic analysis, because it can (indirectly) call is_subtype() etc., and it |
248 |
| - will crash on placeholder types. So we hijack replace_alias_tvars() that was initially |
249 |
| - intended to deal with eager expansion of generic type aliases during semantic analysis. |
| 246 | + Note it is safe to use expand_type() during semantic analysis, because it should never |
| 247 | + (indirectly) call is_subtype(). |
250 | 248 | """
|
251 | 249 | mapped_items = {}
|
252 | 250 | for key in valid_items:
|
253 | 251 | type_in_base = valid_items[key]
|
254 | 252 | if not tvars:
|
255 | 253 | mapped_items[key] = type_in_base
|
256 | 254 | continue
|
257 |
| - mapped_type = replace_alias_tvars( |
258 |
| - type_in_base, tvars, base_args, type_in_base.line, type_in_base.column |
| 255 | + mapped_items[key] = expand_type( |
| 256 | + type_in_base, {t.id: a for (t, a) in zip(tvars, base_args)} |
259 | 257 | )
|
260 |
| - mapped_items[key] = mapped_type |
261 | 258 | return mapped_items
|
262 | 259 |
|
263 | 260 | def analyze_typeddict_classdef_fields(
|
|
0 commit comments