Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4061,7 +4061,11 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:
type_params: TypeVarLikeList | None
all_type_params_names: list[str] | None
if self.check_type_alias_type_call(s.rvalue, name=lvalue.name):
rvalue = s.rvalue.args[1]
rvalue = (
s.rvalue.args[1]
if s.rvalue.arg_kinds[1] == ARG_POS
else s.rvalue.args[s.rvalue.arg_names.index("value")]
)
pep_695 = True
type_params, all_type_params_names = self.analyze_type_alias_type_params(s.rvalue)
else:
Expand Down Expand Up @@ -4249,7 +4253,9 @@ def check_type_alias_type_call(self, rvalue: Expression, *, name: str) -> TypeGu
return False
if not self.check_typevarlike_name(rvalue, name, rvalue):
return False
if rvalue.arg_kinds.count(ARG_POS) != 2:
if rvalue.arg_kinds.count(ARG_POS) != (
2 - ("value" in rvalue.arg_names) - ("name" in rvalue.arg_names)
):
return False

return True
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,14 @@ x: TestType = 42
y: TestType = 'a'
z: TestType = object() # E: Incompatible types in assignment (expression has type "object", variable has type "int | str")

TA = TypeAliasType("TA", value=int)
a: TA = 1
b: TA = 's' # E: Incompatible types in assignment (expression has type "str", variable has type "int")

TA2 = TypeAliasType("TA2", type_params=(), value=int) # shuffled arguments
a2: TA2 = 1
b2: TA2 = 's' # E: Incompatible types in assignment (expression has type "str", variable has type "int")

reveal_type(TestType) # N: Revealed type is "typing_extensions.TypeAliasType"
TestType() # E: "TypeAliasType" not callable

Expand Down