Summary
The preview rule PLR6301 is meant to detect when a method should instead become a staticmethod, class method or a fucntion, and triggering when the self argument in the function body is unused.
The documentation for this rule explains that it doesn't trigger for methods decorated with @typing.override, which is good, however, this detection doesn't work when the override symbol is imported within a TYPE_CHECKING block, and has a fallback in the else block after to just a no-op decorator.
This pattern is pretty important for libraries that need to handle backwards compatibility and don't want to have typing_extensions become a runtime dependency.
E.g.
if TYPE_CHECKING:
from typing_extensions import override
else:
override = lambda f: f
# Ruff doesn't seem to understand that `override` in here is actually the `typing.override`
# and when PLR6301 violation is detected, even if decorated with `@override`, it triggers.
Playground link: https://play.ruff.rs/45ead6a4-9511-49be-bf76-010f6d325a80
Version
ruff 0.15.9
Summary
The preview rule
PLR6301is meant to detect when a method should instead become a staticmethod, class method or a fucntion, and triggering when theselfargument in the function body is unused.The documentation for this rule explains that it doesn't trigger for methods decorated with
@typing.override, which is good, however, this detection doesn't work when theoverridesymbol is imported within aTYPE_CHECKINGblock, and has a fallback in the else block after to just a no-op decorator.This pattern is pretty important for libraries that need to handle backwards compatibility and don't want to have
typing_extensionsbecome a runtime dependency.E.g.
Playground link: https://play.ruff.rs/45ead6a4-9511-49be-bf76-010f6d325a80
Version
ruff 0.15.9