mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +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> |
||
---|---|---|
.. | ||
super.md |