Checking for usual descriptors in Python 2.3

Michael Hudson mwh at python.net
Thu Feb 12 06:34:02 EST 2004


François Pinard <pinard at iro.umontreal.ca> 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. 

> P.S. - If you are curious, my real goal is creating some metaclass
> able to build kind-of-shadow classes for various pygtk widgets,
> lazily, on the fly.  

I'm not sure how this reletes to the above, but have fun :-)

You may find it sensible to just restrict yourself to a finite set of
descriptors you know how to deal with.

Cheers,
mwh

-- 
  I'm a keen cyclist and I stop at red lights.  Those who don't need
  hitting with a great big slapping machine.
                                           -- Colin Davidson, cam.misc



More information about the Python-list mailing list