mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 21:03:11 +00:00
## 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> |
||
|---|---|---|
| .. | ||
| airflow | ||
| control-flow-graph | ||
| eradicate | ||
| fastapi | ||
| filesystem | ||
| flake8_2020 | ||
| flake8_annotations | ||
| flake8_async | ||
| flake8_bandit | ||
| flake8_blind_except | ||
| flake8_boolean_trap | ||
| flake8_bugbear | ||
| flake8_builtins | ||
| flake8_commas | ||
| flake8_comprehensions | ||
| flake8_datetimez | ||
| flake8_debugger | ||
| flake8_django | ||
| flake8_errmsg | ||
| flake8_executable | ||
| flake8_fixme | ||
| flake8_future_annotations | ||
| flake8_gettext | ||
| flake8_implicit_str_concat | ||
| flake8_import_conventions | ||
| flake8_logging | ||
| flake8_logging_format | ||
| flake8_no_pep420 | ||
| flake8_pie | ||
| flake8_print | ||
| flake8_pyi | ||
| flake8_pytest_style | ||
| flake8_quotes | ||
| flake8_raise | ||
| flake8_return | ||
| flake8_self | ||
| flake8_simplify | ||
| flake8_slots | ||
| flake8_tidy_imports | ||
| flake8_todos | ||
| flake8_type_checking | ||
| flake8_unused_arguments | ||
| flake8_use_pathlib | ||
| flynt | ||
| isort | ||
| mccabe | ||
| numpy | ||
| pandas_vet | ||
| pep8_naming | ||
| perflint | ||
| pycodestyle | ||
| pydoclint | ||
| pydocstyle | ||
| pyflakes | ||
| pygrep_hooks | ||
| pylint | ||
| pyupgrade | ||
| refurb | ||
| ruff | ||
| syntax_errors | ||
| tryceratops | ||
| __init__.py | ||