Replies: 1 comment
|
You are right, the aliases in src/httpx2/httpx2/_types.py are all plain assignments: QueryParamTypes = Union[
"QueryParams",
Mapping[str, PrimitiveData | Sequence[PrimitiveData]],
...
]mypy and pyright infer implicit type aliases heuristically, which is why they stay quiet, but stricter checkers like ty want the explicit PEP 613 form before they treat the name as an alias rather than a module-level variable. That matters extra here because most of these unions contain forward-reference strings like "QueryParams". Since the package declares requires-python >= 3.10, the 3.12 from typing import TypeAlias
QueryParamTypes: TypeAlias = Union[
"QueryParams",
Mapping[str, PrimitiveData | Sequence[PrimitiveData]],
list[tuple[str, PrimitiveData]],
tuple[tuple[str, PrimitiveData], ...],
str,
bytes,
]Mechanical change across the ~15 aliases in that file, no runtime impact. Seems like a reasonable small PR if the maintainers are open to it. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The
httpx2._typesmodule (re-exported byhttpx2) contains several type aliases such asQueryParamTypes, defined like so:The issue is that these aliases are not marked as such, neither using
typing.TypeAlias(availabl since Python 3.10) nor with thetypestatement introduced in Python 3.12. This results in e.g. ty complaining "Variable of typeobjectis not allowed in a parameter annotation" when trying to use one of these meant-to-be type aliases as a function parameter type.Given that Python 3.10 is the declared minimum Python version for httpx2 currently, my suggestion would be to annotate these aliases with
TypeAlias, e.g.:All reactions