Evaluating *EVERYTHING*

Steve Purcell stephen_purcell at yahoo.com
Fri Mar 30 02:00:36 EST 2001


David Allen wrote:
> Is there a way to get python to look through a whole
> file and say "Whoa there bucky - I've never heard
> of FoobarExceptoin"


You can never really track down all such possible problems, because the names
used for objects in your python code could (in theory more often than in
practice) be defined only at execution time. As an extreme example, look
at the following:

    >>> raise FoobarException        # not defined yet
    Traceback (innermost last):
      File "<stdin>", line 1, in ?
    NameError: FoobarException
    >>> import new
    >>> setattr(__import__('__main__'), 'FoobarException',                          ...         new.classobj('FoobarException',(Exception,),{}))
    >>> raise FoobarException        # now it's defined
    Traceback (innermost last):
      File "<stdin>", line 1, in ?
    __main__.FoobarException


For that reason, I see things like this: in Python, there's no difference
between a typo and a coding logic mistake, because you won't find either until
you run that code in a test or 'for real'.

-Steve


-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo




More information about the Python-list mailing list