ruff/crates/red_knot_python_semantic
Alex Waygood 55bccf6680
[red-knot] Fix edge case for binary-expression inference where the lhs and rhs are the exact same type (#13823)
## Summary

This fixes an edge case that @carljm and I missed when implementing
https://github.com/astral-sh/ruff/pull/13800. Namely, if the left-hand
operand is the _exact same type_ as the right-hand operand, the
reflected dunder on the right-hand operand is never tried:

```pycon
>>> class Foo:
...     def __radd__(self, other):
...         return 42
...         
>>> Foo() + Foo()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    Foo() + Foo()
    ~~~~~~^~~~~~~
TypeError: unsupported operand type(s) for +: 'Foo' and 'Foo'
```

This edge case _is_ covered in Brett's blog at
https://snarky.ca/unravelling-binary-arithmetic-operations-in-python/,
but I missed it amongst all the other subtleties of this algorithm. The
motivations and history behind it were discussed in
https://mail.python.org/archives/list/python-dev@python.org/thread/7NZUCODEAPQFMRFXYRMGJXDSIS3WJYIV/

## Test Plan

I added an mdtest for this cornercase.
2024-10-19 11:09:54 -07:00
..
resources [red-knot] Fix edge case for binary-expression inference where the lhs and rhs are the exact same type (#13823) 2024-10-19 11:09:54 -07:00
src [red-knot] Fix edge case for binary-expression inference where the lhs and rhs are the exact same type (#13823) 2024-10-19 11:09:54 -07:00
tests [red-knot] document test framework (#13695) 2024-10-10 12:02:01 -07:00
build.rs [red-knot] Add a build.rs file to red_knot_python_semantic, and document pitfalls of using rstest in combination with mdtest (#13747) 2024-10-14 13:02:03 +01:00
Cargo.toml [red knot] Use memmem::find instead of custom version (#13750) 2024-10-14 15:17:19 +02:00