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

Make dual mode GA-specific #429

Open
utensil opened this issue Jun 2, 2020 · 3 comments
Open

Make dual mode GA-specific #429

utensil opened this issue Jun 2, 2020 · 3 comments
Milestone

Comments

@utensil
Copy link
Member

utensil commented Jun 2, 2020

See #425 (comment) . It's good in general but has no particular use case in the near future and it breaks compatibility.

@eric-wieser
Copy link
Member

We may also want to change this API to help with #196 - having separate spellings for getting and setting, val = Ga.dual_mode_value and Ga.dual_mode(val), is a waste of names.

@eric-wieser
Copy link
Member

eric-wieser commented Jun 2, 2020

One way we could perhaps handle that is a class like:

class PropertyAndClassMethod(property):
    def __init__(self, get=None, set=None, del_=None, doc=None, call=None):
        super().__init__(get, set, del_, doc)
        self.fcall = classmethod(call)

    def classmethod(self, f):
        return PropertyAndClassMethod(self.fget, self.fset, self.fdel, self.__doc__, f)

    def __get__(self, obj, owner):
        if obj is None:
            return self.fcall.__get__(obj, owner)
        else:
            return super().__get__(obj, owner)

class Ga:
    _dual_mode = 'default'
    @PropertyAndClassMethod
    def dual_mode(self):
        return self._dual_mode
    @dual_mode.setter
    def dual_mode(self, value):
        self._dual_mode = value
    @dual_mode.classmethod
    def dual_mode(cls, value):
        deprecate()
        cls._dual_mode = value

This will keep Ga.dual_mode("I+") working, but will break o3d.dual_mode("I+") with a TypeError.

@utensil utensil added this to the 0.6.0 milestone Jun 2, 2020
@utensil
Copy link
Member Author

utensil commented Jun 3, 2020

It looks good to me except the name could be something without a "and" and more general, like ExtendableProperty and class method is optional and we could integrate cached_property together as one of the extendable functionalities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants