Order in metaclass

Alex Martelli aleaxit at yahoo.com
Thu Oct 14 09:42:24 CEST 2004


Carlos Ribeiro <carribeiro at gmail.com> wrote:
   ...
> The code is as follows -- still with debug code included, and lots of
comments:

Nice!  I must be missing something (what's the role of the '__attr__'
key you're setdefaulting into instance dicts and never using
otherwise?), and there may be enhanceable spots such as:


>             if (isinstance(fobj,StringType) or
>                 isinstance(fobj,IntType) or
>                 isinstance(fobj,FloatType) or
>                 isinstance(fobj,ListType)):

isinstance accepts a tuple as its 2nd arg exactly to avoid this need;
set once, somewhere,

elementaryTypes = StringType, IntType, FloatType, ListType

and then you can typecheck here with just

              if isinstance(fobj, elementaryTypes):

...but if this, or the recommendation to follow PEP 8 (space after
comma, etc) is the most important suggestion I have to offer about your
code, I guess that's a good sign!-)


Alex



More information about the Python-list mailing list