Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smarie opened this issue Jan 31, 2020 · 0 comments
Open

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

smarie opened this issue Jan 31, 2020 · 0 comments
Labels

Comments

@smarie
Copy link
Owner

smarie commented Jan 31, 2020

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

@smarie smarie changed the title [pyfields] set-only descriptors [pyfields] set-only descriptors (fast-get descriptors) Jan 31, 2020
@smarie smarie changed the title [pyfields] set-only descriptors (fast-get descriptors) Set-only descriptors (fast-get descriptors) Sep 7, 2020
@smarie smarie added the pyfields label Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant