-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
right operand's __radd__ method is ignored when the left operand is a NamedTuple (3.15.0a7) #146592
Copy link
Copy link
Closed as duplicate of#146587
Closed as duplicate of#146587
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
I'm seeing a regression in how an + operation is resolved between a NamedTuple and an arbitrary type with a __radd__ implementation, which looks like an LSP violation since builtin tuple instance still behave the same as with Python 3.14
from typing import NamedTuple
class T(NamedTuple):
x: int
class A:
def __init__(self, *args):
self.lst = list(args)
def __radd__(self, other):
return A(*self.lst, other)
print(((1,)+A()).lst) # [(1,)]
print((T(x=1)+A()).lst) # raisesTraceback (most recent call last):
File "/Users/clm/dev/gh/astropy/astropy/t.py", line 13, in <module>
print((T(x=1)+A()).lst) # raises
~~~~~~^~~~
TypeError: can only concatenate tuple (not "A") to tupleThe __radd__ implementation on the right operand appears to be entirely skipped, and we only see the error from the left operand's __add__ method.
This was originally discovered in astropy's test suite.
xref numpy/numpy#31088
xref astropy/astropy#19503
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error