PEP 696 adds type defaults for TypeVar. It is available in Python 3.12 and loosely supported with the typing_extensions that comes in mypy 1.4+ (technically typing_extensions>=4.4.0).
However, with the next release of mypy we get *exactly* the behavior we want. pyright has supported the new syntax since at least the version we're using in our tests currently.
I tried the code snippet in VSCode and PyLance picks up the same types as the mypy }} playground. I believe the only places we'd need to use {{@overload are the constructors for generic classes that take an optional codec_options, and the with_options methods.
With mypy 1.3.0 -1.5.1, we would have the same behavior as our generics have today. With the next release of mypy we should be able to support strict typing and greatly simplify both our typing implementation and its usage by users.
Assuming this works, we could close PYTHON-3980.
- is depended on by
-
PYTHON-3698 Support mypy --strict testing
- Blocked
- is related to
-
PYTHON-3698 Support mypy --strict testing
- Blocked
- related to
-
MOTOR-1285 Add generics to type stubs
- Closed
-
PYTHON-4796 Update type checkers and handle with_options typing
- Closed