-
Notifications
You must be signed in to change notification settings - Fork 227
Closed
Labels
Milestone
Description
Summary
The following is accepted by mypy and was also working in previous versions of ty:
from typing import Any, Generic, TypeAlias, TypeVar, Union
_JsonValue: TypeAlias = str | int | float | bool | list | dict | None
T = TypeVar("T", bound=_JsonValue)
class JSONTypeHelper(Generic[T]):
def __init__(self) -> None: ...
class StringType(JSONTypeHelper[str]):
def __init__(self) -> None: ...
W = TypeVar("W", bound=JSONTypeHelper)
class ArrayType(JSONTypeHelper[list], Generic[W]):
def __init__(self, wrapped_type: W | type[W], **kwargs: Any) -> None: ...
array = ArrayType(StringType)
# Argument to bound method `__init__` is incorrect: Expected `ArrayType[W@ArrayType]`, found `ArrayType[<class 'StringType'>]` (invalid-argument-type) [Ln 23, Col 9]Curiously, using PEP 695 seems to make ty happy, though unfortunately I need to support Python 3.10+:
from typing import Any, TypeAlias, Union
_JsonValue: TypeAlias = str | int | float | bool | list | dict | None
class JSONTypeHelper[T: _JsonValue]():
def __init__(self) -> None: ...
class StringType(JSONTypeHelper[str]):
def __init__(self) -> None: ...
class ArrayType[W: JSONTypeHelper](JSONTypeHelper[list]):
def __init__(self, wrapped_type: W | type[W], **kwargs: Any) -> None: ...
array = ArrayType(StringType)Version
ty 0.0.1-alpha.26 (b225fd8 2025-11-10)
Reactions are currently unavailable