diff --git a/mypy/semanal.py b/mypy/semanal.py index e90ab9f160e0..42803727a958 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -4157,8 +4157,12 @@ def check_type_alias_type_call(self, rvalue: Expression, *, name: str) -> TypeGu names.append("typing.TypeAliasType") if not refers_to_fullname(rvalue.callee, tuple(names)): return False + if not self.check_typevarlike_name(rvalue, name, rvalue): + return False + if rvalue.arg_kinds.count(ARG_POS) != 2: + return False - return self.check_typevarlike_name(rvalue, name, rvalue) + return True def analyze_type_alias_type_params( self, rvalue: CallExpr diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index c7b9694a9188..4073836dd973 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1105,6 +1105,10 @@ t1: T1 # E: Variable "__main__.T1" is not valid as a type \ T3 = TypeAliasType("T3", -1) # E: Invalid type: try using Literal[-1] instead? t3: T3 reveal_type(t3) # N: Revealed type is "Any" + +T4 = TypeAliasType("T4") # E: Missing positional argument "value" in call to "TypeAliasType" +T5 = TypeAliasType("T5", int, str) # E: Too many positional arguments for "TypeAliasType" \ + # E: Argument 3 to "TypeAliasType" has incompatible type "Type[str]"; expected "Tuple[Union[TypeVar?, ParamSpec?, TypeVarTuple?], ...]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-full.pyi]