Neat way to get descriptor object
问题 In Python 3 class A(object): attr = SomeDescriptor() ... def somewhere(self): # need to check is type of self.attr is SomeDescriptor() desc = self.__class__.__dict__[attr_name] return isinstance(desc, SomeDescriptor) Is there better way to do it? I don't like this self.__class__.__dict__ stuff 回答1: A.attr causes Python to call SomeDescriptor().__get__(None, A) so if you have SomeDescriptor.__get__ return self when inst is None , then A.attr will return the descriptor: class SomeDescriptor():