annoying behavior
Elbert Lev
elbertlev at hotmail.com
Wed Sep 29 00:10:31 EDT 2004
Michael Hoffman <m.h.3.9.1.without.dots.at.cam.ac.uk at example.com> wrote in message news:<cjcqao$ji0$1 at gemini.csx.cam.ac.uk>...
> Elbert Lev wrote:
>
> > I think, it would be good, if some sort of warning is given during
> > import, but not during instantiating the instance of the class. At
> > least in a "debug" mode. What really did happen: the bug was reported
> > after the scrip was running for 30 minutes. PyCheck finds it
> > immediatelly. Why not to do the same kind of check in the interpreter?
>
> Can you post the results of your PyChecker run and the exact input to it?
>
> I just did a test myself:
>
> """
> $ cat test1.py
> class X(object):
> def __init__(self):
> self.f()
> self.r = True
>
> def f(self):
> print self.r
>
> def main():
> x = X()
>
> $ pychecker test1.py
> Processing test1...
>
> Warnings...
>
> test1.py:10: Local variable (x) not used
> """
>
> I think that what you want the Python compiler to do is harder than you
> think it is, and not all cases will be caught unless you actually run
> the program.
>
> I've forgotten to assign attributes and variables before using them in
> the past--it's just something you have to learn not to do.
Here it is:
Processing test...
C:\Python23\python.exe
C:\Python23\Lib\site-packages\pychecker\checker.py
test.py
Caught exception importing module test:
File "C:\Python23\Lib\site-packages\pychecker\checker.py", line
576, in setupMainCode()
module = imp.load_module(self.moduleName, file, filename, smt)
File "test.py", line 16
f = foo("1234")
File "test.py", line 5, in __init__()
self.f()
File "test.py", line 9, in f()
if self.r:
AttributeError: foo instance has no attribute 'r'
Warnings...
test:1: NOT PROCESSED UNABLE TO IMPORT
> I think that what you want the Python compiler to do is harder than you
> think it is, and not all cases will be caught unless you actually run
> the program.
Sure not all! I tell you more: in many cases after the program was
used for years, it contains errors. This does not stop people debuging
them :) Even if check does not finds all errors it will be very good.
Isn't this what Python is about - fast and fun programming, not
frustration. After all, if I want troubles, I always can use C or Java
:))
More information about the Python-list
mailing list