ruff/crates/red_knot_python_semantic/resources/mdtest/comparison
David Peter 86b01d2d3c
[red-knot] Correct modeling of dunder calls (#16368)
## Summary

Model dunder-calls correctly (and in one single place), by implementing
this behavior (using `__getitem__` as an example).

```py
def getitem_desugared(obj: object, key: object) -> object:
    getitem_callable = find_in_mro(type(obj), "__getitem__")
    if hasattr(getitem_callable, "__get__"):
        getitem_callable = getitem_callable.__get__(obj, type(obj))

    return getitem_callable(key)
```

See the new `calls/dunder.md` test suite for more information. The new
behavior also needs much fewer lines of code (the diff is positive due
to new tests).

## Test Plan

New tests; fix TODOs in existing tests.
2025-02-25 20:38:15 +01:00
..
instances [red-knot] Correct modeling of dunder calls (#16368) 2025-02-25 20:38:15 +01:00
byte_literals.md [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
identity.md Improve mdtests style (#14884) 2024-12-10 13:05:51 +00:00
integers.md Refactor `CallOutcome` to `Result` (#16161) 2025-02-18 13:34:39 +01:00
intersections.md Refactor `CallOutcome` to `Result` (#16161) 2025-02-18 13:34:39 +01:00
non_bool_returns.md Refactor `CallOutcome` to `Result` (#16161) 2025-02-18 13:34:39 +01:00
strings.md Improve mdtests style (#14884) 2024-12-10 13:05:51 +00:00
tuples.md [red-knot] Diagnostics for incorrect `bool` usages (#16238) 2025-02-21 19:26:05 +01:00
unions.md Improve mdtests style (#14884) 2024-12-10 13:05:51 +00:00
unsupported.md Refactor `CallOutcome` to `Result` (#16161) 2025-02-18 13:34:39 +01:00