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 Property.__get__ return self if instance is None #936

Closed
gemerden opened this issue Jan 21, 2022 · 1 comment
Closed

make Property.__get__ return self if instance is None #936

gemerden opened this issue Jan 21, 2022 · 1 comment

Comments

@gemerden
Copy link

Currently the property descriptor cannot be called on the owner class, with error: AttributeError: 'NoneType' object has no attribute '__node__'. Calling the property on the class can be very useful for introspection. Also it is easily fixed bij changing:

class Property(object):
    def __get__(self, instance, owner):
        value = instance.__node__[self.key]
        if value is None:
            value = self.default
        return value

in:

class Property(object):
    def __get__(self, instance, owner):
        if instance is None:
            return self
        value = instance.__node__[self.key]
        if value is None:
            value = self.default
        return value

This is very common in descriptors.

@motey
Copy link

motey commented Apr 8, 2022

dup #784

@motey motey closed this as completed Apr 8, 2022
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