Skip to content

Set-only descriptors (fast-get descriptors) #6

@smarie

Description

@smarie

Currently in python there exist descriptors with the __get__ and not the __set__ (nor __delete__). They are called "non-data descriptors" and are used to put a hook on get, but to allow users to replace the attribute entirely easily.

In certain cases the opposite could be interesting to have: a descriptor with hooks on __set__ but none on __get__ for fast access. However it would require some kind of a convention on the name where the actual value to return would reside, so not easy to propose a way to enter this information.
An alternative is simply to propose a "fast get" implementer method like this:

class MyDescriptor:
    __get__ = native_read_attr('value')  # <-- this mark would enable fast get

    def __set__(self, obj, value):
        ...(hooks)
        obj.value = value

See also smarie/python-pyfields#18

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions