Skip to content

Commit bfc1a76

Browse files
authored
Rename type alias helper with a misleading name (#15199)
1 parent b69060a commit bfc1a76

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

mypy/checkexpr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
from mypy.traverser import has_await_expression
103103
from mypy.typeanal import (
104104
check_for_explicit_any,
105-
expand_type_alias,
106105
has_any_from_unimported_type,
106+
instantiate_type_alias,
107107
make_optional_type,
108108
set_any_tvars,
109109
)
@@ -3965,12 +3965,12 @@ def visit_type_application(self, tapp: TypeApplication) -> Type:
39653965
39663966
There are two different options here, depending on whether expr refers
39673967
to a type alias or directly to a generic class. In the first case we need
3968-
to use a dedicated function typeanal.expand_type_alias(). This
3969-
is due to some differences in how type arguments are applied and checked.
3968+
to use a dedicated function typeanal.instantiate_type_alias(). This
3969+
is due to slight differences in how type arguments are applied and checked.
39703970
"""
39713971
if isinstance(tapp.expr, RefExpr) and isinstance(tapp.expr.node, TypeAlias):
39723972
# Subscription of a (generic) alias in runtime context, expand the alias.
3973-
item = expand_type_alias(
3973+
item = instantiate_type_alias(
39743974
tapp.expr.node,
39753975
tapp.types,
39763976
self.chk.fail,

mypy/typeanal.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool)
398398
an_args = self.pack_paramspec_args(an_args)
399399

400400
disallow_any = self.options.disallow_any_generics and not self.is_typeshed_stub
401-
res = expand_type_alias(
401+
res = instantiate_type_alias(
402402
node,
403403
an_args,
404404
self.fail,
@@ -408,7 +408,7 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool)
408408
unexpanded_type=t,
409409
disallow_any=disallow_any,
410410
)
411-
# The only case where expand_type_alias() can return an incorrect instance is
411+
# The only case where instantiate_type_alias() can return an incorrect instance is
412412
# when it is top-level instance, so no need to recurse.
413413
if (
414414
isinstance(res, Instance) # type: ignore[misc]
@@ -714,7 +714,7 @@ def analyze_type_with_type_info(
714714
# The class has a Tuple[...] base class so it will be
715715
# represented as a tuple type.
716716
if info.special_alias:
717-
return expand_type_alias(
717+
return instantiate_type_alias(
718718
info.special_alias,
719719
# TODO: should we allow NamedTuples generic in ParamSpec?
720720
self.anal_array(args),
@@ -730,7 +730,7 @@ def analyze_type_with_type_info(
730730
# The class has a TypedDict[...] base class so it will be
731731
# represented as a typeddict type.
732732
if info.special_alias:
733-
return expand_type_alias(
733+
return instantiate_type_alias(
734734
info.special_alias,
735735
# TODO: should we allow TypedDicts generic in ParamSpec?
736736
self.anal_array(args),
@@ -1713,7 +1713,7 @@ def fix_instance(
17131713
t.invalid = True
17141714

17151715

1716-
def expand_type_alias(
1716+
def instantiate_type_alias(
17171717
node: TypeAlias,
17181718
args: list[Type],
17191719
fail: MsgCallback,
@@ -1725,11 +1725,13 @@ def expand_type_alias(
17251725
disallow_any: bool = False,
17261726
use_standard_error: bool = False,
17271727
) -> Type:
1728-
"""Expand a (generic) type alias target following the rules outlined in TypeAlias docstring.
1728+
"""Create an instance of a (generic) type alias from alias node and type arguments.
17291729
1730+
We are following the rules outlined in TypeAlias docstring.
17301731
Here:
1731-
target: original target type
1732-
args: types to be substituted in place of type variables
1732+
node: type alias node (definition)
1733+
args: type arguments (types to be substituted in place of type variables
1734+
when expanding the alias)
17331735
fail: error reporter callback
17341736
no_args: whether original definition used a bare generic `A = List`
17351737
ctx: context where expansion happens

0 commit comments

Comments
 (0)