Update UP035 for Python 3.13
AlexWaygood opened this issue · comments
We should update UP035 to emit a diagnostic if --target-version=py313
has been selected and a user imports typing.TypeIs
, warnings.deprecated
, typing.ReadOnly
, typing.NoDefault
typing.get_protocol_members
or typing.is_protocol
from typing_extensions
rather than typing
Originally posted by @AlexWaygood in #11411 (comment)
Other updates that are required
- We should emit an error if
TypeVar
,ParamSpec
orTypeVarTuple
is imported fromtyping_extensions
and the script targets py313+ (but not if the script targets lower versions) - We should not emit an error if the script targets py312 or lower, and any of
TypedDict
,Protocol
,runtime_checkable
orget_type_hints
is imported fromtyping_extensions
. These all have their implementations from Python 3.13 backported intyping_extensions
. (We currently do emit errors for all of these; this is a false positive.)
Lastly, for (Async)Generator
and (Async)ContextManager
, we should recommend for the user to import them from collections.abc
or contextlib
rather than typing_extensions
on Python 3.9-3.12 (and not emit a diagnostic at all on Python <=3.8). Currently if we see a user importing then from typing_extensions
, we tell the user to import them from typing
instead, but that's no longer a good suggestion. The typing_extensions
versions backport the typing
versions from Python 3.13, but on Python 3.9-3.12, the collections.abc
/contextlib
versions should still be a dropin replacement.