"Compile time" checking?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Aug 10 22:06:17 CEST 2005

In <1123689195.840622.158870 at z14g2000cwz.googlegroups.com>, Qopit wrote:

> Hi there,
> I'm pretty new to Python and am trying to figure out how to get "will
> this code compile?"-like code checking.  To me this is a pretty basic
> language/environment requirement, especially when working with large
> projects.  It is *much* better to catch errors at "compile-time" rather
> than at run-time.

Might sound harsh, but then python ist the wrong language for you.

> One thing I've "found" is the PyChecker module (conveniently embedded
> in SPE), but it doesn't seem to do that great of a job.  For example,
> the following simple program checks out perfectly as far as PyChecker
> is concerned:
> #----
> def tester(a,b,c):
>   print "bogus test function",a,b,c
> tester(1,2,3)  #this runs fine
> tester(1,2)    #this obviously causes a run-time TypeError exception
> #----
> It seems to me that this should be an obvious catch for PyChecker.

It's just obviuos because you know that the first call to `tester()`
doesn't change the name binding for `tester` to a callable object that
also accepts just two parameters.  You, as a human, can see easily the
error here, but a program has to follow all possible control flows to be
sure about that.  And that's most of the time very complex and sometimes
impossible.  It's not enough to look just at the signature of the function.

Simple (?) test::

  def tester(a, b, c):
      global tester
      print "bogus test function", a, b, c
      def tester(a, b):
          print "other test function", a, b

  tester(1, 2, 3) # This runs fine.
  tester(1, 2)    # This too.

> Any other comments appreciated (aside from things like "just right good
> code that doesn't have bugs like that" :) ).

Compile it by running it and write unit tests.

	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list