[SciPy-dev] a suggest patch for the traits package

David C. Morrill dmorrill at enthought.com
Mon Apr 7 13:57:31 CDT 2003


Trent:

Thanks for the suggestions/patches! I don't see any problem with adding any
of your changes...I'll see if I can do it later today.

As to the indenting, Eric and I have agreed that the indenting needs to be
"fixed" to be Python standard, but until now no one other than me has been
looking at the code. Now that someone else is, maybe I'll fix it in the near
future. Thanks for the reminder :-)

BTW, over the week-end I just finished the first draft of the "Traits User's
Guide" (about 60 pages long). I'll be getting it up on the website sometime
this week, but if you're interested I can send you something sooner (PDF or
.doc). Let me know if you're interested...

Regards,
Dave Morrill

----- Original Message -----
From: "Trent Mick" <trentm at ActiveState.com>
To: <scipy-dev at scipy.net>
Sent: Thursday, April 03, 2003 6:04 PM
Subject: [SciPy-dev] a suggest patch for the traits package


>
> This is directed mainly at David Morrill. Hi David, we met at PyCon if
you'll
> remember.
>
> I have started using your Traits package in some scripts of mine
> (I quite like it), and have a few of questions/suggested changes:
>
> 1. TraitFunction optionally allows for an "info" attribute on the
>    validation function to specify a more specific description than "a
>    legal value". How about using the function's docstring (if it exists)
>    for "info":
>
> --- traits.py.orig  Thu Apr 03 14:17:08 2003
> +++ traits.py   Thu Apr 03 14:14:03 2003
> @@ -904,8 +904,10 @@
>     def info ( self ):
>         try:
>            return self.aFunc.info
>         except:
> +          if self.aFunc.__doc__:
> +             return self.aFunc.__doc__
>            return 'a legal value'
>
>
#---------------------------------------------------------------------------
-----
>  #  'TraitEnum' class:
> End of Patch.
>
>    This patch still allows an "info" attribute to override the
>    docstring if you think that that is valueable to maintain. If not, if
>    wouldn't break any of my code to drop the 'aFunc.info' option in
>    favor of using the docstring. :)
>
>
> 2. Trait.do_list() does not currently translate a MethodType object
>    (i.e. a class method) to a TraitFunction. I think it should:
>
> --- traits.py.orig  Thu Apr 03 14:17:08 2003
> +++ traits.py   Thu Apr 03 14:49:47 2003
> @@ -341,9 +341,10 @@
>                elif typeItem == DictType:
>                   map.update( item )
>                elif typeItem == ClassType:
>                   other.append( TraitInstance( item ) )
> -              elif typeItem == FunctionType:
> +              elif (typeItem == FunctionType or
> +                    typeItem == MethodType):
>                   other.append( TraitFunction( item ) )
>                elif (isinstance( item, TraitHandler )  or
>                      isinstance( item, TraitDelegate ) or
>                      isinstance( item, Trait )):
> End of Patch.
>
>
>    What do you think? These two patches allow one to do something like
>    the following:
>
>         from traits import *
>
>         class CheechAndChong(HasTraits):
>             __traits__ = {"badges": None}
>             def __init__(self):
>                 self.__traits__["badges"] = (self.validate_badges,)
>             def validate_badges(self, object, name, value):
>                 "nuthin'"
>                 if not value:
>                     return value
>                 raise ValueError("we don't need no stinkin' badges")
>
>         c = CheechAndChong()
>         c.badges = 2
>
>     raises this error string:
>
>         traits.traits.TraitError: The 'badges' trait of a CheechAndChong
instance must be nuthin', but a value of 2 was specified.
>
>
> 3. The mixed tab spacing in the .py files makes it very difficult to
>    edit these files. Would you consider standardizing on 4 space
>    indentations? If so I would be happy to do a lot of the leg work to
>    reindent. (Actually, I think reindent.py in the Python source tree
>    will do most of that leg work automatically.)
>
>
> Cheers,
> Trent
>
> --
> Trent Mick
> TrentM at ActiveState.com
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev




More information about the Scipy-dev mailing list