Skip to content

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

Open

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

Activity

  1. changed the title [-][pyfields] set-only descriptors[/-] [+][pyfields] set-only descriptors (fast-get descriptors)[/+] on Jan 31, 2020
  2. changed the title [-][pyfields] set-only descriptors (fast-get descriptors)[/-] [+]Set-only descriptors (fast-get descriptors)[/+] on Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions