mirror of
https://github.com/micropython/micropython.git
synced 2026-04-29 12:20:12 +02:00
1834dcf8b5
Properly cast tuple subclasses to the native base class before performing `__add__` or `__iadd_`. Closes: #7304 Signed-off-by: Jeff Epler <jepler@unpythonic.net>
63 lines
696 B
Python
63 lines
696 B
Python
try:
|
|
from collections import namedtuple
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
|
|
class MyTuple(tuple):
|
|
pass
|
|
|
|
|
|
N = namedtuple("N", ("a", "b"))
|
|
|
|
|
|
class MyNamedTuple(N):
|
|
pass
|
|
|
|
|
|
t = (1, 2)
|
|
m = MyTuple((3, 4))
|
|
n = N(5, 6)
|
|
q = MyNamedTuple(7, 8)
|
|
|
|
print(t + t)
|
|
print(t + m)
|
|
print(t + n)
|
|
print(t + q)
|
|
|
|
print(m + t)
|
|
print(m + m)
|
|
print(m + n)
|
|
print(m + q)
|
|
|
|
print(n + t)
|
|
print(n + m)
|
|
print(n + n)
|
|
print(n + q)
|
|
|
|
print(q + t)
|
|
print(q + m)
|
|
print(q + n)
|
|
print(q + q)
|
|
|
|
print(t < t)
|
|
print(t < m)
|
|
print(t < n)
|
|
print(t < q)
|
|
|
|
print(m < t)
|
|
print(m < m)
|
|
print(m < n)
|
|
print(m < q)
|
|
|
|
print(n < t)
|
|
print(n < m)
|
|
print(n < n)
|
|
print(n < q)
|
|
|
|
print(q < t)
|
|
print(q < m)
|
|
print(q < n)
|
|
print(q < q)
|