ruff/crates/red_knot_python_semantic/resources/mdtest
cake-monotone 649610cc98
[red-knot] Support super (#17174)
## 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>
2025-04-16 18:41:55 +00:00
..
annotations [red-knot] optimize building large unions of literals (#17403) 2025-04-16 13:55:37 +00:00
assignment [red-knot] Don't infer Todo for quite so many tuple type expressions (#17116) 2025-04-01 15:44:02 +01:00
binary [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
boolean [red-knot] Statically known branches (#15019) 2024-12-21 11:33:10 +01:00
boundness_declaredness [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
call [red-knot] set a size limit on unions of literals (#17419) 2025-04-16 14:23:11 +00:00
class [red-knot] Support super (#17174) 2025-04-16 18:41:55 +00:00
comparison [red-knot] Do not assume that x != 0 if x inhabits ~Literal[0] (#17370) 2025-04-15 22:27:27 -07:00
comprehensions [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
conditional [red-knot] visibility_constraint analysis for match cases (#17077) 2025-04-03 11:15:33 +00:00
declaration [red-knot] Avoid undeclared path when raising conflicting declarations (#14958) 2024-12-17 09:49:39 +05:30
diagnostics [red-knot] Document current state of attribute assignment diagnostics (#16746) 2025-03-14 20:34:43 +01:00
directives [red-knot] Add support for assert_never (#17287) 2025-04-08 09:31:49 +02:00
doc red_knot_python_semantic: replace one use of "old" secondary diagnostic messages 2025-04-10 13:21:00 -04:00
exception [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
expression [red-knot] Add initial support for * imports (#16923) 2025-03-24 17:15:58 +00:00
function red_knot_python_semantic: remove the "old" secondary message type 2025-04-10 13:21:00 -04:00
generics [red-knot] Acknowledge that T & anything is assignable to T (#17413) 2025-04-15 16:34:07 -04:00
import [red-knot] Add some knowledge of __all__ to *-import machinery (#17373) 2025-04-15 12:56:40 +01:00
literal [red-knot] Migrate bool/str/repr unit tests to Markdown tests (#15534) 2025-01-16 11:21:56 -08:00
loops [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
narrow [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
regression [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
scopes [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
shadowing [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
snapshots [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
stubs [red-knot] Allow explicit specialization of generic classes (#17023) 2025-04-09 11:18:46 -04:00
subscript [red-knot] Decorators and properties (#17017) 2025-04-02 09:27:46 +02:00
suppressions Use python.typing.org for typing documentation links (#17323) 2025-04-09 20:38:20 +02:00
type_of [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
type_properties [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
type_qualifiers [red-knot] Preliminary tests for typing.Final (#15917) 2025-03-14 12:30:13 +01:00
unary [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
with [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
.mdformat.toml [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
attributes.md [red-knot] Support super (#17174) 2025-04-16 18:41:55 +00:00
dataclasses.md [red-knot] Initial support for dataclasses (#17353) 2025-04-15 10:39:21 +02:00
decorators.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
descriptor_protocol.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
final.md [red-knot] Add support for @final classes (#15070) 2024-12-19 21:02:14 +00:00
intersection_types.md [red-knot] add test cases result in false positive errors (#16856) 2025-03-20 17:17:54 +00:00
invalid_syntax.md [red-knot] Understand typing.Callable (#16493) 2025-03-08 03:58:52 +00:00
known_constants.md [red-knot] Add rule invalid-type-checking-constant (#16501) 2025-03-04 19:49:34 +00:00
mdtest_config.md [red-knot] Add missing imports in mdtests (#15869) 2025-02-03 09:27:29 +00:00
mdtest_custom_typeshed.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
metaclass.md [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
mro.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
pep695_type_aliases.md [red-knot] Decorators and properties (#17017) 2025-04-02 09:27:46 +02:00
properties.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
protocols.md [red-knot] Make' Type::in_type_expression()' exhaustive for Type::KnownInstance (#16836) 2025-03-19 07:36:28 -07:00
slots.md [red-knot] fix: improve type inference for binary ops on tuples (#16725) 2025-03-14 12:29:57 +01:00
statically_known_branches.md [red-knot] Reachability analysis (#17199) 2025-04-08 08:37:20 +02:00
sys_platform.md [red-knot] Specialize str.startswith for string literals (#17351) 2025-04-11 16:26:45 +02:00
sys_version_info.md [red-knot] Decorators and properties (#17017) 2025-04-02 09:27:46 +02:00
terminal_statements.md [red-knot] Avoid unresolved-reference in unreachable code (#17169) 2025-04-03 16:52:11 +02:00
type_api.md [red-knot] Fix comments in type_api.md (#17425) 2025-04-16 11:19:48 +00:00
union_types.md [red-knot] add special case for float/complex (#16166) 2025-02-14 12:24:10 -08:00
unpacking.md [red-knot] Support unpacking with target (#16469) 2025-03-08 02:36:35 +00:00
unreachable.md [red-knot] Document limitations of diagnostics-silencing in unreachable code (#17387) 2025-04-14 12:55:14 +02:00