467,892 Members | 1,868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,892 developers. It's quick & easy.

Checking for usual descriptors in Python 2.3

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...
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. If experimentation shows that this is not speedy enough, than
I may rather have a pre-processor that would produce Python source
instead. In any case, I need to learn how to explore descriptors at run
time, rather than working hard at scanning/parsing real pygtk sources.

--
François Pinard http://www.iro.umontreal.ca/~pinard

Jul 18 '05 #1
  • viewed: 1585
Share:
2 Replies
François Pinard <pi****@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
Jul 18 '05 #2
Michael Hudson <mw*@python.net> writes:
François Pinard <pi****@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.


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.

HTH,
mwh

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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Denis S. Otkidach | last post: by
6 posts views Thread by Jeff Duffy | last post: by
8 posts views Thread by David S. | last post: by
reply views Thread by Steven Bethard | last post: by
12 posts views Thread by bruno at modulix | last post: by
3 posts views Thread by redefined.horizons | last post: by
7 posts views Thread by mrkafk | last post: by
1 post views Thread by Chris Leary | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.