astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.

Home Page:https://docs.astral.sh/ruff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 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.)

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.