[Python-Dev] Issue #26204: compiler now emits a SyntaxWarning on constant statement (original) (raw)
Georg Brandl g.brandl at gmx.net
Tue Feb 9 06:55:11 EST 2016
- Previous message (by thread): [Python-Dev] Issue #26204: compiler now emits a SyntaxWarning on constant statement
- Next message (by thread): [Python-Dev] Syntax Highlightning for C API of CPython in VIM
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 02/09/2016 10:57 AM, Joseph Martinot-Lagarde wrote:
Victor Stinner <victor.stinner gmail.com> writes:
Hi, I changed the Python compiler to ignore any kind "constant expressions", whereas it only ignored strings and integers before: http://bugs.python.org/issue26204 The compiler now also emits a SyntaxWarning on such case. IMHO the warning can help to detect bugs for developers who just learnt Python. The warning is not emited for strings, since triple quoted strings are a common syntax for multiline comments. The warning is not emited neither for ellispis (...) since "f(): ..." is a legit syntax for abstract function. I frequently use 1/0 as a quick break in a script or a program (it's even more useful with post-mortem debugging). Would it be considered as a constant and ignored instead of raising a ZeroDivisionError ?
At first, expressions involving operators are not seen as constant. But 1/2 would be removed, since the peepholer will evaluate it to 0.5 (or 0) and the constant-removal pass will recognize it as a constant (assuming this ordering of the passes).
In the case of 1/0 the peepholer will try to evaluate it, but get an exception and therefore not touch the expression further.
cheers, Georg
- Previous message (by thread): [Python-Dev] Issue #26204: compiler now emits a SyntaxWarning on constant statement
- Next message (by thread): [Python-Dev] Syntax Highlightning for C API of CPython in VIM
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]