By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Checking for usual descriptors in Python 2.3

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.