mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-05 08:00:27 +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> |
||
---|---|---|
.. | ||
test | ||
__init__.py |