Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fail check if not enough or too many types provided to `TypeAlia…
…sType` (#18308) Fixes #18307 by failing a type alias call check if the number of positional arguments isn't exactly 2 (one for the type name as a literal string, one for the target type to alias). Before: ```python from typing_extensions import TypeAliasType T1 = TypeAliasType("T1", int, str) # Silently passes and uses `int` as the target type, should be an error T2 = TypeAliasType("T2") # Crashes ``` After: ```python T1 = TypeAliasType("T1", int, str) # E: Too many positional arguments for "TypeAliasType" T2 = TypeAliasType("T2") # E: Missing positional argument "value" in call to "TypeAliasType" ``` The error messages above are propagated from a check with the [`TypeAliasType` constructor definition from the stubs](https://github.com/python/typeshed/blob/bd728fbfae18395c37d9fd020e31b1d4f30c6136/stdlib/typing.pyi#L1041-L1044), so no further special-casing is necessary: ```python class TypeAliasType: def __init__( self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = () ) -> None: ... ```
- Loading branch information