mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
![]() ## Summary closes #16615 This PR includes: - Introduces a new type: `Type::BoundSuper` - Implements member lookup for `Type::BoundSuper`, resolving attributes by traversing the MRO starting from the specified class - Adds support for inferring appropriate arguments (`pivot_class` and `owner`) for `super()` when it is used without arguments When `super(..)` appears in code, it can be inferred into one of the following: - `Type::Unknown`: when a runtime error would occur (e.g. calling `super()` out of method scope, or when parameter validation inside `super` fails) - `KnownClass::Super::to_instance()`: when the result is an *unbound super object* or when a dynamic type is used as parameters (MRO traversing is meaningless) - `Type::BoundSuper`: the common case, representing a properly constructed `super` instance that is ready for MRO traversal and attribute resolution ### Terminology Python defines the terms *bound super object* and *unbound super object*. An **unbound super object** is created when `super` is called with only one argument (e.g. `super(A)`). This object may later be bound via the `super.__get__` method. However, this form is rarely used in practice. A **bound super object** is created either by calling `super(pivot_class, owner)` or by using the implicit form `super()`, where both arguments are inferred from the context. This is the most common usage. ### Follow-ups - Add diagnostics for `super()` calls that would result in runtime errors (marked as TODO) - Add property tests for `Type::BoundSuper` ## Test Plan - Added `mdtest/class/super.md` --------- Co-authored-by: Carl Meyer <carl@astral.sh> |
||
---|---|---|
.. | ||
red_knot | ||
red_knot_ide | ||
red_knot_project | ||
red_knot_python_semantic | ||
red_knot_server | ||
red_knot_test | ||
red_knot_vendored | ||
red_knot_wasm | ||
ruff | ||
ruff_annotate_snippets | ||
ruff_benchmark | ||
ruff_cache | ||
ruff_db | ||
ruff_dev | ||
ruff_diagnostics | ||
ruff_formatter | ||
ruff_graph | ||
ruff_index | ||
ruff_linter | ||
ruff_macros | ||
ruff_notebook | ||
ruff_python_ast | ||
ruff_python_ast_integration_tests | ||
ruff_python_codegen | ||
ruff_python_formatter | ||
ruff_python_index | ||
ruff_python_literal | ||
ruff_python_parser | ||
ruff_python_resolver | ||
ruff_python_semantic | ||
ruff_python_stdlib | ||
ruff_python_trivia | ||
ruff_python_trivia_integration_tests | ||
ruff_server | ||
ruff_source_file | ||
ruff_text_size | ||
ruff_wasm | ||
ruff_workspace |