ruff/crates/ruff_linter/resources/test/fixtures
Igor Drokin 54df73c9f7
[pyupgrade] Apply UP008 only when the __class__ cell exists (#19424)
## Summary

Resolves #19357 

Skip UP008 diagnostic for `builtins.super(P, self)` calls when
`__class__` is not referenced locally, preventing incorrect fixes.

**Note:** I haven't found concrete information about which cases
`__class__` will be loaded into the scope. Let me know if anyone has
references, it would be useful to enhance the implementation. I did a
lot of tests to determine when `__class__` is loaded. Considered
sources:
1. [Python doc
super](https://docs.python.org/3/library/functions.html#super)
2. [Python doc classes](https://docs.python.org/3/tutorial/classes.html)
3. [pep-3135](https://peps.python.org/pep-3135/#specification)

As I understand it, Python will inject at runtime into local scope a
`__class__` variable if it detects references to `super` or `__class__`.
This allows calling `super()` and passing appropriate parameters.
However, the compiler doesn't do the same for `builtins.super`, so we
need to somehow introduce `__class__` into the local scope.

I figured out `__class__` will be in scope with valid value when two
conditions are met:
1. `super` or `__class__` names have been loaded within function scope
4. `__class__` is not overridden.

I think my solution isn't elegant, so I would be appreciate a detailed
review.

## Test Plan

Added 19 test cases, updated snapshots.

---------

Co-authored-by: Igor Drokin <drokinii1017@gmail.com>
2025-09-09 14:59:23 -04:00
..
airflow [airflow] Move airflow.operators.postgres_operator.Mapping from AIR302 to AIR301 (#20172) 2025-09-03 10:18:17 -04:00
control-flow-graph
eradicate Don't flag pyrefly pragmas as unused code (ERA001) (#19731) 2025-08-04 10:15:37 +02:00
fastapi [fastapi] Fix false positive for paths with spaces around parameters (FAST003) (#20077) 2025-08-29 13:40:25 +00:00
filesystem
flake8_2020
flake8_annotations
flake8_async [flake8-async] Implement blocking-input rule (ASYNC250) (#20122) 2025-08-28 11:04:24 -07:00
flake8_bandit Disallow implicit concatenation of t-strings and other string types (#19485) 2025-07-27 12:41:03 +00:00
flake8_blind_except [flake8-blind-except] Fix BLE001 false-positive on raise ... from None (#19755) 2025-08-13 13:01:47 -04:00
flake8_boolean_trap
flake8_bugbear [flake8-bugbear] Fix B017 false negatives for keyword exception arguments (#19217) 2025-07-11 16:43:09 +00:00
flake8_builtins
flake8_commas [flake8-commas] Add support for trailing comma checks in type parameter lists (COM812,COM819) (#19390) 2025-07-28 10:53:04 -04:00
flake8_comprehensions [flake8-comprehensions] Skip C417 when lambda contains yield/yield from (#20201) 2025-09-03 16:39:11 -04:00
flake8_datetimez
flake8_debugger
flake8_django [flake8_django] Fix DJ008 false positive for abstract models with type-annotated abstract field (#19221) 2025-07-11 16:50:59 +00:00
flake8_errmsg [flake8-errmsg] Exclude typing.cast from EM101 (#19656) 2025-08-01 13:37:44 -04:00
flake8_executable
flake8_fixme
flake8_future_annotations
flake8_gettext Add t-string fixtures for rules that do not need to be modified (#19146) 2025-07-14 09:46:31 -05:00
flake8_implicit_str_concat
flake8_import_conventions
flake8_logging
flake8_logging_format [flake8-logging-format] Add auto-fix for f-string logging calls (G004) (#19303) 2025-08-26 10:51:24 -04:00
flake8_no_pep420
flake8_pie Fix F701 to F707 errors in tests (#19125) 2025-07-04 13:43:18 -05:00
flake8_print
flake8_pyi [flake8-pyi] Preserve inline comment in ellipsis removal (PYI013) (#19399) 2025-07-29 15:06:04 -04:00
flake8_pytest_style Less confidently mark f-strings as empty when inferring truthiness (#20152) 2025-08-29 22:12:54 +00:00
flake8_quotes
flake8_raise
flake8_return [flake8-return] Fix false-positive for variables used inside nested functions in RET504 (#18433) 2025-07-10 16:10:22 -04:00
flake8_self
flake8_simplify [flake8-simplify] Implement fix for maxsplit without separator (SIM905) (#19851) 2025-08-15 15:18:06 -04:00
flake8_slots
flake8_tidy_imports
flake8_todos
flake8_type_checking [flake8-type-checking, pyupgrade, ruff] Add from __future__ import annotations when it would allow new fixes (TC001, TC002, TC003, UP037, RUF013) (#19100) 2025-07-16 08:50:52 -04:00
flake8_unused_arguments Add t-string fixtures for rules that do not need to be modified (#19146) 2025-07-14 09:46:31 -05:00
flake8_use_pathlib [flake8-use-pathlib] Add autofix for PTH211 (#20009) 2025-08-22 12:38:37 -05:00
flynt
isort [isort] Handle multiple continuation lines after module docstring (I002) (#19818) 2025-08-15 17:17:50 -04:00
mccabe
numpy
pandas_vet
pep8_naming [pep8-naming] Fix N802 false positives for CGIHTTPRequestHandler and SimpleHTTPRequestHandler (#19432) 2025-07-23 12:04:11 -04:00
perflint [perflint] Handle tuples in dictionary comprehensions (PERF403) (#19934) 2025-08-28 21:37:40 +00:00
pycodestyle [pycodestyle] Preserve return type annotation for ParamSpec (E731) (#20108) 2025-08-28 20:31:45 +00:00
pydoclint
pydocstyle [pydoclint] Fix SyntaxError from fixes with line continuations (D201, D202) (#19246) 2025-07-14 13:31:36 -04:00
pyflakes [pyflakes] Fix allowed-unused-imports matching for top-level modules (F401) (#20115) 2025-08-28 13:02:50 +00:00
pygrep_hooks
pylint [pylint] Add U+061C to PLE2502 (#20106) 2025-08-28 16:35:48 -04:00
pyupgrade [pyupgrade] Apply UP008 only when the __class__ cell exists (#19424) 2025-09-09 14:59:23 -04:00
refurb [refurb] Mark int and bool cases for Decimal.from_float as safe fixes in FURB164 tests (#19468) 2025-07-28 14:21:38 +00:00
ruff [ruff] Use helper function for empty f-string detection in in-empty-collection (RUF060) (#20249) 2025-09-04 20:20:59 +00:00
syntax_errors [syntax-errors] Detect yield from inside async function (#20051) 2025-09-03 10:13:05 -04:00
tryceratops
__init__.py