Skip to content

Commit b7712e4

Browse files
committed
GR-31986: add missing impl of _collections._tuplegetter
- was causing namedtuples to revert to using a property which cannot be pickled
1 parent 5c4faed commit b7712e4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

graalpython/lib-graalpython/_collections.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,34 @@ def __reduce__(self):
5656

5757

5858
defaultdict.__module__ = 'collections'
59+
60+
61+
class _tuplegetter(object):
62+
def __init__(self, index, doc):
63+
self.index = index
64+
self.__doc__ = doc
65+
66+
@__graalpython__.builtin_method
67+
def __set__(self, instance, value):
68+
raise AttributeError("can't set attribute")
69+
70+
@__graalpython__.builtin_method
71+
def __delete__(self, instance):
72+
raise AttributeError("can't delete attribute")
73+
74+
@__graalpython__.builtin_method
75+
def __get__(self, instance, owner=None):
76+
index = self.index
77+
if not isinstance(instance, tuple):
78+
if instance is None:
79+
return self
80+
raise TypeError("descriptor for index '%d' for tuple subclasses "
81+
"doesn't apply to '%s' object", index, instance)
82+
if index >= len(instance):
83+
raise IndexError("tuple index out of range")
84+
85+
return instance[index]
86+
87+
@__graalpython__.builtin_method
88+
def __reduce__(self):
89+
return type(self), (self.index, self.__doc__)

0 commit comments

Comments
 (0)