mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 04:48:06 +00:00
[ruff] Added cls.__dict__.get('__annotations__') check (RUF063) (#18233)
Added `cls.__dict__.get('__annotations__')` check for Python 3.10+ and
Python < 3.10 with `typing-extensions` enabled.
Closes #17853
<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:
- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
requests.)
- Does this pull request include references to any relevant issues?
-->
## Summary
Added `cls.__dict__.get('__annotations__')` check for Python 3.10+ and
Python < 3.10 with `typing-extensions` enabled.
## Test Plan
`cargo test`
---------
Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
f544026b81
commit
e66f182045
11 changed files with 391 additions and 0 deletions
18
crates/ruff_linter/resources/test/fixtures/ruff/RUF063.py
vendored
Normal file
18
crates/ruff_linter/resources/test/fixtures/ruff/RUF063.py
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# RUF063
|
||||
# Cases that should trigger the violation
|
||||
|
||||
foo.__dict__.get("__annotations__") # RUF063
|
||||
foo.__dict__.get("__annotations__", None) # RUF063
|
||||
foo.__dict__.get("__annotations__", {}) # RUF063
|
||||
foo.__dict__["__annotations__"] # RUF063
|
||||
|
||||
# Cases that should NOT trigger the violation
|
||||
|
||||
foo.__dict__.get("not__annotations__")
|
||||
foo.__dict__.get("not__annotations__", None)
|
||||
foo.__dict__.get("not__annotations__", {})
|
||||
foo.__dict__["not__annotations__"]
|
||||
foo.__annotations__
|
||||
foo.get("__annotations__")
|
||||
foo.get("__annotations__", None)
|
||||
foo.get("__annotations__", {})
|
||||
Loading…
Add table
Add a link
Reference in a new issue