determining context of getattr

Tripp Lilley tripp at perspex.com
Mon Aug 21 00:53:10 EDT 2000


Is there any way to know inside of a getattr call whether or not the
returned object will be immediately subjected to a __call__ invocation?

ie: if I do this:

	foo.say( )

can foo's __getattr__ know that whatever it returns for 'say' is going
to immediately be __call__'ed?

Right now, I'm doing a very nasty, overhead-laden hack in which I have
wrapper classes for all of the primitive types, that implement coercion,
etc., so that the returned objects "act" like primitives when subjected
to math, but "act" like methods when __call__'ed (ie: __call__ simply
returns the "value" of the object).

I vaguely recall hearing something about Py3k making primitive types
into real, first-class objects that I might subclass to effect this
behaviour. Any truth to that recollection of mine? ie:

	class TrippInt (int):
		def __call__ (self):
			return self.__value__

which would let me do this:

	foo.value = TrippInt( 42 )

	print foo.value
	print foo.value + 9
	print foo.value( )
	print foo.value( ) + 9


Thanks!

-- 
Tripp Lilley * tripp at perspex.com *
http://stargate.eheart.sg505.net/~tlilley/
-----------------------------------------------------------------------------
"This whole textual substitution thing is pissing me off.
 I feel like I'm programming in Tcl."

- Eric Frias, former roommate, hacking partner extraordinaire



More information about the Python-list mailing list