Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable=syntax-error doesn't work #986

Closed
bradfriedman opened this issue Jul 7, 2016 · 13 comments
Closed

disable=syntax-error doesn't work #986

bradfriedman opened this issue Jul 7, 2016 · 13 comments

Comments

@bradfriedman
Copy link

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.

@dmtucker
Copy link

dmtucker commented Jul 7, 2016

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'

@bradfriedman
Copy link
Author

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

@The-Compiler
Copy link
Contributor

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.

@PCManticore
Copy link
Contributor

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

@PCManticore
Copy link
Contributor

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?

@PCManticore
Copy link
Contributor

Closing this, since it is the expected behavior.

@dmtucker should be fixed now with 1.6.1.

@dmtucker
Copy link

dmtucker commented Jul 7, 2016

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

@syagev
Copy link

syagev commented Jun 24, 2019

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?

@JoshMayberry
Copy link

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.

@MarcoGorelli
Copy link
Contributor

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?

As mentioned above, these wouldn't parse without IPython as a dependency, as they're not valid Python syntax. ast.parse will crash, you'd need IPython's TransformerManager to parse such code.

As a workaround, you could use nbQA to run pylint on notebooks:

pip install -U nbqa
nbqa pylint notebook.ipynb

disclaimer: I'm the author of nbQA

@Pierre-Sassoulas
Copy link
Member

Labelled as "won't fix", because as @MarcoGorelli said there is an external solution and jupyter notebook are not pylint's core competency.

@alex-eri
Copy link

Labelled as "won't fix", because as @MarcoGorelli said there is an external solution and jupyter notebook are not pylint's core competency.

I want to pylint code with cython parts, where want to skip parts. Maybe preprocessing brackets?

import asyncio
# pylint: off
include "server.pxi"
# pylint: on
import logging

@Pierre-Sassoulas
Copy link
Member

Can you open another issue for cython please @alex-eri ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants