Not understood error with __set_name__ in a descriptor class

Peter Otten __peter__ at web.de
Sun Apr 19 12:38:04 EDT 2020


Unknown wrote:

> Le 19/04/2020 à 17:06, ast a écrit :
> 
> I understood where the problem is.
> 
> Once __get__ is defined, it is used to read self._name in method
> __set_name__ and it is not défined yet. That's why I have
> an error "'NoneType' object is not callable"
> Thats a nice bug.

It's the fget attribute that is None. You can verify that by setting it to 
something else:

class my_property:
    def __init__(self, fget=None, fset=None, fdel=None):
        self.fget = "fget"
        ...

> I need to think for a workaround

__get__() usually returns self if it's called on the class:

def __get__(self, instance, owner):
    if instance is None:
        return self
    ...



More information about the Python-list mailing list