fix: fail check if not enough or too many types provided to `TypeAlia… by bzoracler · Pull Request #18308 · python/mypy (original) (raw)
…sType()`
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:
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:
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, so no further special-casing is necessary:
class TypeAliasType:
def __init__(
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
) -> None: ...