__getattr__ / __setattr__ - infinite recursion!?
Terry Reedy
tjreedy at udel.edu
Tue Mar 28 18:00:29 EST 2000
"Warren Postma" <embed at geocities.com> wrote in message
news:0yMD4.624$HG1.20784 at nnrp1.uunet.ca...
>
>
> Okay my first attempt at a "static type checking object" for Python blows
> up, probably
> a stack overflow, probably due to infinite recursion or some such
thing....
Yes. Within __setattr__(), you should use explicit references to
self.__dict__[attribute]
instead of self.attribute, which may lead to recursive calls to
__setatttr__. Probably ditto for __getattr__.
> # "type objects"
> int_type = type(0)
> string_type = type("X")
> float_type = type(0.1)
You can also use 'type' module ('import type' or 'from type import *'),
which supplies IntType, etc, including some types that most people would
have difficulty creating innocuous instances of.
> def keyname(self):
> return self.keyname
self.keyname will always directly reference the attribute (fine by me)
instead of this 'get' method.
Terry J. Reedy
More information about the Python-list
mailing list