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

--error-mode seems to enable --py3k errors even when the latter flag is not given #1869

Closed
noonedeadpunk opened this issue Feb 7, 2018 · 5 comments
Labels
Milestone

Comments

@noonedeadpunk
Copy link

Steps to reproduce

  1. Create file with content: print("Hello, world!")
  2. Launch pylint for python 2.7 with arguments "--enable=E --reports=n" and check this file

Current behavior

As a result of check, pylint output following result:

$ /usr/bin/pylint --enable=E --reports=n   test.py
No config file found, using default configuration
************* Module test
C:  1, 0: Unnecessary parens after 'print' keyword (superfluous-parens)
C:  1, 0: Missing module docstring (missing-docstring)
E:  1, 0: print statement used (print-statement)

Expected behavior

Python 2.7 doesn't require using of print() function. Moreover, when I'm actually using print() function instead of print statement, pylint still raises error message.

pylint --version output

$ pylint --version
No config file found, using default configuration
pylint 1.8.2, 
astroid 1.6.1
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609]

Bug raised in VS Code python module, which by default uses pylint: microsoft/vscode-python#722
Also it was discussed here microsoft/vscode#43024

@dstromberg
Copy link

dstromberg commented Feb 7, 2018 via email

@noonedeadpunk
Copy link
Author

noonedeadpunk commented Feb 7, 2018

Yep, it works, but it looks like a workaround.

I may even replace print() with sys.stdout.write() . Nevertheless, I believe, that pylint marks usage of print() function as an error incorrectly, as it's correct usage in python. Moreover, pylint gives conflicting results: from one side parens are unnecessary for print, and from the other side print is used as statement.

So if this is the only solution and this problem is well-known I would be very grateful for the reference to some PEP with recommends to use print_function from the __future__, as I thought that it's ok to use print() without importing future

@dstromberg
Copy link

dstromberg commented Feb 7, 2018 via email

@PCManticore
Copy link
Contributor

So what happens here is that print-statement belongs to the Python 3 porting checker. When you the -E flag, you also enable the --py3k setting, which contains errors and messages related to Python 3 compatibility (https://github.com/PyCQA/pylint/blob/9d23fab60bb5405fde4b081f980693f0b797f41c/pylint/lint.py). This should be enabled though only when the config specifies the --py3k flag, which is not the case as seen from the minimal data you pasted. As @dstromberg mentioned, a workaround for now would be to use the __future__ import.

@PCManticore PCManticore changed the title print statement and function are treated as error --error-mode seems to enable --py3k errors even when the latter flag is not given Feb 8, 2018
@PCManticore PCManticore added this to the 1.9 milestone May 10, 2018
@PCManticore
Copy link
Contributor

Actually I was wrong. You enabled all the error checks by using --enable=E. The error mode is enable with -E, which doesn't take in account the python 3 porting checks.

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

No branches or pull requests

3 participants