ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Update UP035 for Python 3.13

Open AlexWaygood opened this issue 1 year ago • 2 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 https://github.com/astral-sh/ruff/issues/11411#issuecomment-2108265396

AlexWaygood avatar May 13 '24 17:05 AlexWaygood

Other updates that are required

  • We should emit an error if TypeVar, ParamSpec or TypeVarTuple is imported from typing_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 or get_type_hints is imported from typing_extensions. These all have their implementations from Python 3.13 backported in typing_extensions. (We currently do emit errors for all of these; this is a false positive.)

AlexWaygood avatar May 13 '24 17:05 AlexWaygood

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.

AlexWaygood avatar May 13 '24 17:05 AlexWaygood