On 3/29/22 14:41, Christopher Barker wrote:
> Ethan Furman queried:
>> The `__dict__` is needed to store the field names -- did you add `__dict__`
to the
>> `__slots__`?
>
> Nope — though the error indicated that I couldn’t add anything to __slots__
when subclassing tuple. But I may have
> misunderstood the error.
Ah, that's right -- it's saying that *instances* cannot have anything in
`__slots__`, but the class can still have fields:
>>> class Tuple(tuple):
... this = 'eggs'
... that = 'spam'
... __slots__ = ()
... def __new__(cls, *args):
... return tuple.__new__(cls, *args)
...
>>> t = Tuple((1,))
>>> t
(1,)
>>> t.this
'eggs'
>>> t.that
'spam'
So the Tuple class would have properties that redirect to the correct offset -- but that would require a different tuple
class for each field configuration.
--
~Ethan~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/IHOJQLM5KZIKC6TNKZCYHQ25MICBIIW5/
Code of Conduct: http://python.org/psf/codeofconduct/