Files
codeql/python/ql/src/Imports/SyntaxError.qhelp
2018-11-19 15:10:42 +00:00

40 lines
1.5 KiB
XML

<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p> Syntax errors prevent a module being evaluated and thus imported.
An attempt to import a module with invalid syntax will fail; a <code>SyntaxError</code> will be raised.</p>
<p> A common cause of syntax errors is the difference in syntax between Python 2
and Python 3. In particular, a syntax error may be alerted if a Python 3 file is
assumed to be compatible with Python 2 (or vice versa). Explicitly specifying
the expected Python version can help prevent this.
</p>
<p>The existence of a syntax error in a module may suggest other problems as well.
Either the module is never imported in practice and could be deleted or a
<code>try</code> statement around the import is mistakenly discarding the <code>SyntaxError</code>.
</p>
</overview>
<recommendation>
<p>Fixing the syntax error is the obvious fix.
However, it is worth investigating why a module containing a syntax error
was able to persist and address that problem as well.
</p>
<p>If you suspect that the syntax error is caused by the analysis using the
wrong version of Python, consider specifying the version explicitly. For
LGTM.com, you can customize extraction using an <code>lgtm.yml</code> file as
described <a href="https://lgtm.com/help/lgtm/python-extraction">here</a>.
</p>
</recommendation>
<references>
<li>Python Tutorial: <a href="http://docs.python.org/tutorial/errors.html#syntax-errors">SyntaxErrors.</a></li>
</references>
</qhelp>