Checking for usual descriptors in Python 2.3

Michael Hudson mwh at
Thu Feb 12 12:43:47 CET 2004

Michael Hudson <mwh at> writes:

> François Pinard <pinard at> writes:
> > This question is a bit technical, but hopefully, this list will offer me
> > good hints or nice solutions.  Happily enough for me, it often does! :-)
> > 
> > I would need to recognise and play with descriptor types, like:
> > 
> >     member descriptors
> >     method descriptors
> >     getset descriptors
> >     wrapper descriptors
> > 
> > but do not find how to easily refer to them, either from existing
> > constructor types (like we could do with `property', say), nor from
> > members of the `types' module.  I also wonder how much I can "get into"
> > these various descriptors or tear them apart...
> If you want to know whether 'ob' is a descriptor, 
>     hasattr(ob, '__get__')
> is pretty close.  PEP 252 is also your friend. 

On the off chance that this wasn't what you were asking (:-) and you
wanted to get your hands on the type objects of each of the given
descriptor types, the only way I can think of doing that is getting
your hands on one and calling type() on it.

member: type(type.__dict__['__dictoffset__'])
method: type(list.append)
getset: type(object.__dict__['__class__'])
wrapper: type(object.__dict__['__getattribute__'])

As to how introspectable each of these are, the interactive
interpreter (or the source) is now your friend.


  If you don't use emacs, you're a pathetic, mewling, masochistic
  weakling and I can't be bothered to convert you.    -- Ron Echeverri

More information about the Python-list mailing list