--- *Zaur Shibzukhov*
2018-09-03 1:02 GMT+03:00 Wes Turner <wes.tur...@gmail.com>: > > On Sunday, September 2, 2018, Zaur Shibzukhov <szp...@gmail.com> wrote: > >> >> >> --- >> *Zaur Shibzukhov* >> >> >> 2018-09-02 22:11 GMT+03:00 Wes Turner <wes.tur...@gmail.com>: >> >>> Does the value of __hash__ change when attributes of a recordclass >>> change? >>> >> >> Currently recordclass's __hash__ didn't implemented. >> > > https://docs.python.org/3/glossary.html#term-hashable > > https://docs.python.org/3/reference/datamodel.html#object.__hash__ > > http://www.attrs.org/en/stable/hashing.html > There is correction: recordclass and it's base memoryslots didn't implement __hash__, but memoryslots implement richcompare (almost as python's list). > > >> >>> On Sunday, September 2, 2018, Zaur Shibzukhov <szp...@gmail.com> wrote: >>> >>>> As the author of `recordclass` I would like to shed some light... >>>> >>>> Recorclass originated as a response to the [question]( >>>> https://stackoverflow.com/questions/29290359/exis >>>> tence-of-mutable-named-tuple-in-python/29419745#29419745) on >>>> stackoverflow. >>>> >>>> `Recordclass` was conceived and implemented as a type that, by api, >>>> memory and speed, would be completely identical to` namedtuple`, except >>>> that it would support an assignment in which any element could be replaced >>>> without creating a new instance, as in ` namedtuple`. Those. would be >>>> almost identical to `namedtuple` and support the assignment (` __setitem__` >>>> / `setslice__`). >>>> >>>> The effectiveness of namedtuple is based on the effectiveness of the >>>> `tuple` type in python. In order to achieve the same efficiency it was >>>> necessary to create a type `memoryslots`. Its structure >>>> (`PyMemorySlotsObject`) is identical to the structure of` tuple` >>>> (`PyTupleObject`) and therefore takes up the same amount of memory as` >>>> tuple`. >>>> >>>> `Recordclass` is defined on top of` memoryslots` just like `namedtuple` >>>> above` tuple`. Attributes are accessed via a descriptor >>>> (`itemgetset`), which supports both` __get__` and `__set__` by the element >>>> index. >>>> >>>> The class generated by `recordclass` is: >>>> >>>> `` ` >>>> from recordclass import memoryslots, itemgetset >>>> >>>> class C (memoryslots): >>>> __slots__ = () >>>> >>>> _fields = ('attr_1', ..., 'attr_m') >>>> >>>> attr_1 = itemgetset (0) >>>> ... >>>> attr_m = itemgetset (m-1) >>>> >>>> def __new __ (cls, attr_1, ..., attr_m): >>>> 'Create new instance of {typename} ({arg_list})' >>>> return memoryslots .__ new __ (cls, attr_1, ..., attr_m) >>>> `` ` >>>> etc. following the `namedtuple` definition scheme. >>>> >>>> As a result, `recordclass` takes up as much memory as` namedtuple`, it >>>> supports quick access by `__getitem__` /` __setitem__` and by attribute >>>> name via the protocol of the descriptors. >>>> >>>> Regards, >>>> >>>> Zaur >>>> >>>> суббота, 1 сентября 2018 г., 10:48:07 UTC+3 пользователь Martin Bammer >>>> написал: >>>>> >>>>> Hi, >>>>> >>>>> what about adding recordclass >>>>> (https://bitbucket.org/intellimath/recordclass) to the collections >>>>> module >>>>> >>>>> It is like namedtuple, but elements are writable and it is written in >>>>> C >>>>> and thus much faster. >>>>> >>>>> And for convenience it could be named as namedlist. >>>>> >>>>> Regards, >>>>> >>>>> Martin >>>>> >>>>> >>>>> _______________________________________________ >>>>> Python-ideas mailing list >>>>> python...@python.org >>>>> https://mail.python.org/mailman/listinfo/python-ideas >>>>> Code of Conduct: http://python.org/psf/codeofconduct/ >>>>> >>>> >>
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/