On 9/4/2018 3:03 PM, Chris Barker via Python-ideas wrote:
Chiming in here:

dataclasses was just added to the stdlib.

I understand that record class is not the same thing, but the use cases do overlap a great deal.

So I think the cord goal for anyone that wants to see this in the stdlib is to demonstrate tbat recordclass
Adds significant enough value to justify something so similar.

I've seen three things mentioned that might be different from dataclasses:
- instance size
- speed (not sure of what: instance creation? field access?)
- iterating over fields

But I've not seen concrete examples of the first two where dataclasses doesn't perform well enough. For the third one, there's already a thread on this mailing list: "Consider adding an iterable option to dataclass". I'm contemplating adding it.

Personally, I don’t see it.

I'm skeptical, too.

Eric


-CHB

On Tue, Sep 4, 2018 at 2:04 PM Zaur Shibzukhov <[email protected] <mailto:[email protected]>> wrote:



    ---
    /Zaur Shibzukhov/


    2018-09-03 1:02 GMT+03:00 Wes Turner <[email protected]
    <mailto:[email protected]>>:


        On Sunday, September 2, 2018, Zaur Shibzukhov <[email protected]
        <mailto:[email protected]>> wrote:



            ---
            /Zaur Shibzukhov/


            2018-09-02 22:11 GMT+03:00 Wes Turner <[email protected]
            <mailto:[email protected]>>:

                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
                <[email protected] <mailto:[email protected]>> 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/existence-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
                        [email protected]
                        https://mail.python.org/mailman/listinfo/python-ideas

                        Code of Conduct:
                        http://python.org/psf/codeofconduct/



    _______________________________________________
    Python-ideas mailing list
    [email protected] <mailto:[email protected]>
    https://mail.python.org/mailman/listinfo/python-ideas
    Code of Conduct: http://python.org/psf/codeofconduct/

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected] <mailto:[email protected]>


_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to