Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fail check if not enough or too many types provided to `TypeAlia… #18308

Merged
merged 2 commits into from
Dec 19, 2024
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
6 changes: 5 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -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?], ...]"
bzoracler marked this conversation as resolved.
Show resolved Hide resolved
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]

Expand Down
Loading