ruff/crates
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
..
red_knot Upgrade salsa (#13757) 2024-10-15 11:06:32 +00:00
red_knot_python_semantic [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
red_knot_server Upgrade to Rust 1.82 (#13816) 2024-10-19 16:05:50 +02:00
red_knot_test [red-knot] Port type inference tests to new test framework (#13719) 2024-10-15 11:23:46 -07:00
red_knot_vendored Sync vendored typeshed stubs (#13753) 2024-10-15 13:36:11 +00:00
red_knot_wasm Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
red_knot_workspace [red-knot] Infer target types for unpacked tuple assignment (#13316) 2024-10-15 19:07:11 +00:00
ruff Changelog for Ruff v0.7 (#13794) 2024-10-17 16:14:21 +00:00
ruff_benchmark [red-knot] Add control flow for try/except blocks (#13729) 2024-10-16 13:03:59 +00:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_dev Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_diagnostics [Minor typo] Fix article in "an fix" (#12797) 2024-08-10 21:22:00 -04:00
ruff_formatter Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_graph Upgrade salsa (#13757) 2024-10-15 11:06:32 +00:00
ruff_index [red-knot] small efficiency improvements and bugfixes to use-def map building (#12373) 2024-07-18 09:24:58 -07:00
ruff_linter Upgrade to Rust 1.82 (#13816) 2024-10-19 16:05:50 +02:00
ruff_macros Upgrade to Rust 1.82 (#13816) 2024-10-19 16:05:50 +02:00
ruff_notebook Allow ipytest cell magic (#13745) 2024-10-14 15:48:33 +05:30
ruff_python_ast [red-knot] binary arithmetic on instances (#13800) 2024-10-19 15:22:54 +00:00
ruff_python_ast_integration_tests [internal] ComparableExpr (f)strings and bytes made invariant under concatenation (#13301) 2024-09-25 16:58:57 +02:00
ruff_python_codegen Implement iter(), len() and is_empty() for all display-literal AST nodes (#12807) 2024-08-12 10:39:28 +00:00
ruff_python_formatter Upgrade to Rust 1.82 (#13816) 2024-10-19 16:05:50 +02:00
ruff_python_index Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
ruff_python_literal
ruff_python_parser Short circuit lex_identifier if the name is longer or shorter than any known keyword (#13815) 2024-10-19 11:07:15 +00:00
ruff_python_resolver
ruff_python_semantic Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_python_stdlib Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_python_trivia [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_python_trivia_integration_tests
ruff_server Upgrade to Rust 1.82 (#13816) 2024-10-19 16:05:50 +02:00
ruff_source_file Fix off-by one error in the LineIndex::offset calculation (#13407) 2024-09-19 11:58:45 +00:00
ruff_text_size [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_wasm Changelog for Ruff v0.7 (#13794) 2024-10-17 16:14:21 +00:00
ruff_workspace Remove allow-unused-imports setting from the common lint options (#13677) 2024-10-17 16:35:12 +01:00