[Python-Dev] Can Python implementations reject semantically invalid expressions?
Nick Coghlan
ncoghlan at gmail.com
Fri Jul 2 13:47:18 CEST 2010
On Fri, Jul 2, 2010 at 4:55 PM, Craig Citro <craigcitro at gmail.com> wrote:
> Honestly, though, I'd come down on the side of letting the compiler
> raise an error -- while I understand that it means you have
> *different* behavior, I think it's *preferable* behavior.
But you would be taking a module that will compile and making it uncompilable.
The Python code:
def f():
return 1 + "1"
has fully defined runtime semantics: when f() is called, it will raise
TypeError. A module containing this code is still perfectly valid
Python (e.g. the Python test suite does that kind of thing a lot in
tests of the core interpreter semantics).
A Python implementation issuing a SyntaxWarning over this would be
fine, but triggering a SyntaxError would not be valid. However, I'd be
inclined to leave this kind of check to tools like pychecker and
pylint.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list