Pylint: disable=syntax-error doesn't work

Created on 7 Jul 2016  路  9Comments  路  Source: PyCQA/pylint

Steps to reproduce

  1. Write some python code with a syntax error
  2. Add the disable=syntax-error directive to that line

    Current behavior

The syntax error on the line is ignored.

Expected behavior

The syntax error is still reported.

Most helpful comment

Hi all. My use case for this (which I think is valid and useful) is when running pylint on .py files which are used as jupyter notebooks. These files then sometimes have magic commands:

#%%
%load_ext autoreload
%autoreload 2

which obviously doesn't make for valid python syntax but are useful to have inline in the file. It's very useful to have the rest of the notebook linted so ignoring it locally could be great. Would you reconsider?

All 9 comments

What version of Pylint? I am observing a strange error related to inline disabling with Pylint 1.6.0 that I never saw with 1.5.6:

# pylint: disable=unused-argument
[E0012(bad-option-value), ] Bad option value 'unused-argument'

Hmm, my version output shows 1.4.3 for PyLint. Not sure if this repros in a more recent version.

If a SyntaxError occurs, pylint can't parse the file at all - so there's no way it could ignore the error on that line only.

@dmtucker there is a problem with the current release, a new bug fix is coming shortly (half an hour hopefully)

Thanks for the report @bradfriedman

This is actually expected. As @The-Compiler said, if the file cannot be parsed, then we cannot ignore the error at all. But why do you want to disable a syntax-error in the first case?

Closing this, since it is the expected behavior.

@dmtucker should be fixed now with 1.6.1.

@PCManticore Thanks! I am no longer seeing the error.

Hi all. My use case for this (which I think is valid and useful) is when running pylint on .py files which are used as jupyter notebooks. These files then sometimes have magic commands:

#%%
%load_ext autoreload
%autoreload 2

which obviously doesn't make for valid python syntax but are useful to have inline in the file. It's very useful to have the rest of the notebook linted so ignoring it locally could be great. Would you reconsider?

I have some files used by Dundas BI, which is similar to what @syagev has- except the variables are flanked on each side by a dollar sign like this:

print($node_id$)
x = $y$ + $z$

It would be great if I could at least disable pylint from running on those files using disable-all or skip-page as a comment at the top of the page.

Perhaps, if there was a syntax error it could read the first line of the module as plain text. If the first line had a comment with disable-all or skip-page, then don't output the syntax-error message.

Was this page helpful?
0 / 5 - 0 ratings