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

print statement is highlighted by pylint #722

Closed
noonedeadpunk opened this issue Feb 7, 2018 · 26 comments · Fixed by #975 or #954
Closed

print statement is highlighted by pylint #722

noonedeadpunk opened this issue Feb 7, 2018 · 26 comments · Fixed by #975 or #954
Assignees
Labels
area-linting bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@noonedeadpunk
Copy link

Environment data

VS Code version: 1.19.3
Python Extension version: 2018.1
Python Version: 2.7, 3.5
OS and version: OS independent

Actual behavior

pylint marks print statement and print() function are marked as error on both python 2.7 and python 3.5. This behavior appeared just after module upgrade to 2018.1

Expected behavior

pylint shouldn't mark error if using print() function on any python version and print statement on python 2.7

Steps to reproduce:

  • create new .py file
  • enter print("Hello, world!")
  • save file
    Screenshot

Logs

Output from Python output panel

[pylint]E1601:print statement used (1, 1)

Output from Console window (Help->Developer Tools menu)

console.ts:123 [Extension Host] Python Extension: Failed to get conda info from conda null
t.log @ console.ts:123
console.ts:123 [Extension Host] (node:16735) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
@MikhailArkhipov
Copy link

This is PyLint message. Extension simply outputs what PyLint produces. In 2.7 the message should appear according to PyLint docs:
https://pylint.readthedocs.io/en/latest/technical_reference/features.html

print-statement (E1601):
  print statement used (print is a function in Python 3)

However, it should not appear in 3+ then. You can suppress the message in pylintrc file.

@MikhailArkhipov MikhailArkhipov self-assigned this Feb 7, 2018
@noonedeadpunk
Copy link
Author

noonedeadpunk commented Feb 7, 2018

But it seems, that according to pylint, this message should be printed only if print is used as the statement, while it marks as an error while using print as a function.

Moreover, I couldn't reproduce this with system pylint (which is installed on the same machine, as the affected VS Code):

dimar@SVTech-Workstation:~/Documents/Python$ /usr/bin/pylint --version
No config file found, using default configuration
pylint 1.5.2, 
astroid 1.4.4
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609]
dimar@SVTech-Workstation:~/Documents/Python$ /usr/bin/pylint 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)


Report
======
1 statements analysed.

Statistics by type
------------------

+---------+-------+-----------+-----------+------------+---------+
|type     |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module   |1      |1          |=          |0.00        |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|class    |0      |0          |=          |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|method   |0      |0          |=          |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|function |0      |0          |=          |0           |0        |
+---------+-------+-----------+-----------+------------+---------+



Raw metrics
-----------

+----------+-------+------+---------+-----------+
|type      |number |%     |previous |difference |
+==========+=======+======+=========+===========+
|code      |1      |50.00 |NC       |NC         |
+----------+-------+------+---------+-----------+
|docstring |0      |0.00  |NC       |NC         |
+----------+-------+------+---------+-----------+
|comment   |0      |0.00  |NC       |NC         |
+----------+-------+------+---------+-----------+
|empty     |1      |50.00 |NC       |NC         |
+----------+-------+------+---------+-----------+



Duplication
-----------

+-------------------------+------+---------+-----------+
|                         |now   |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines      |0     |NC       |NC         |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |NC       |NC         |
+-------------------------+------+---------+-----------+



Messages by category
--------------------

+-----------+-------+---------+-----------+
|type       |number |previous |difference |
+===========+=======+=========+===========+
|convention |2      |0        |+2.00      |
+-----------+-------+---------+-----------+
|refactor   |0      |0        |=          |
+-----------+-------+---------+-----------+
|warning    |0      |0        |=          |
+-----------+-------+---------+-----------+
|error      |0      |1        |-1.00      |
+-----------+-------+---------+-----------+



Messages
--------

+-------------------+------------+
|message id         |occurrences |
+===================+============+
|superfluous-parens |1           |
+-------------------+------------+
|missing-docstring  |1           |
+-------------------+------------+



Global evaluation
-----------------
Your code has been rated at -10.00/10

dimar@SVTech-Workstation:~/Documents/Python$

And if I replace print() with a statement, only "Missing module docstring (missing-docstring)" notification will stay. So this is possible only if the module uses it's own pylint, which is different version from the system one.

It seems, that it's my fault about reporting problem for python3 - pylint just hadn't re-read the file after changing Python version. So this problem is referenced only to python2.

@zerkms
Copy link

zerkms commented Feb 7, 2018

@noonedeadpunk run pylint with these arguments

--disable=all --enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode --reports=n --output-format=text --msg-template='{line},{column},{category},{msg_id}:{msg}'

@noonedeadpunk
Copy link
Author

@zerkms Yep, you're right, enabling "E" raises "print statement used". Most likely, that vscode-python used other list of enabled modules before update, as this problem appeared only after module update.

And it's pretty irritating, as all of projects are highlighted due to "print statement used". But it seems, that the problem should be addressed to the pylint.

@zerkms
Copy link

zerkms commented Feb 7, 2018

@noonedeadpunk if you report it to the pylink could you please post a link here

@noonedeadpunk
Copy link
Author

@zerkms it seems, that this actual problem with pylint started some time ago, but only now it started to annoy in vscode. Probably you know if --enable=E (or probably some other option) was added by default with the module update?

So, from __future__ import print_function resolves problem, but it looks more like workaround, than the real solution.

@zerkms
Copy link

zerkms commented Feb 7, 2018

I personally use logger instead of print ;-)

@noonedeadpunk
Copy link
Author

Actually, something is really became wrong with pylint after module upgrade. I suppose, that the point is in the default flags for pylint.

So, when I enabled all flags locally for file, which were kindly provided by @zerkms I recieved the following result (which is absolutely correct, except print statement error, which is seemed to be really pylint problem, when -E(--error-mode) flag is used):
screenshot

But if I will remove this pylint options string, all other notifications will be suppressed. If I will remove print() statement, pylint won't display suppressed problems at all.
And I am 100% sure, that these notifications were shown before the module update

@Omegastick
Copy link

In this update, PyLint also stopped highlighting missing docstrings for me. Not sure if it's related or not.

@evanwang22
Copy link

I've been experiencing a similar issue since the latest update to 2018.1. All print statements trigger E1601:print statement used despite explicitly disabling print-statement in my .pylintrc at the project level. Additionally, "Convention" messages no longer show in VSCode (which could be similar to @Omegastick's issue, as missing-docstring is a Convention-level rule)

screen shot 2018-02-14 at 11 47 57 am

screen shot 2018-02-14 at 11 48 28 am

screen shot 2018-02-14 at 11 48 43 am

As the screenshots show, pylint within VSCode and running pylint from the CLI give me different outputs. Happy to provide more detail if it's helpful

@MikhailArkhipov
Copy link

The message comes straight from from pylint. It flags both statement and the function in 2.7. It does not flag function in 3+ but does flag the statement.

I found that

  • changing interpreters did not re-run linting. I am fixing this.
  • changing pylintrc and saving it does not re-run linting. This may be non-trivial to fix since we can't watch all the possible pylintrc locations. Alternative is to add command 'run lint' for the manual activation.

So far I see if I disable the warning in pylintrc it does go away. It also does not appear in Python 3+ (in 2018.1 you'd have to reopen the file after changing interpreters or edit and save the document)

Python 2.7
image

Python 3.6
image

Disabled:
image

@noonedeadpunk
Copy link
Author

noonedeadpunk commented Feb 14, 2018

The problem is, that in this release, you've changed flags with which pylint is launched. So the most of messages from pylint just suppressed in VS code.

It stopped displaying at least trailing-whitespace, trailing-newlines, missing-final-newline, line-too-long, missing-docstring, etc. These are pretty good notifications, and I don't see the reason to disable them.

To reproduce it just try to place the following code, from the screenshot screenshot

It shows the problems only because of the string:
# pylint: enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode

If you remove it, these messages won't be displayed.

@MikhailArkhipov
Copy link

This change is by design since many people don't care about whitespace or styling. In many editors these kind of reports are off by default. There is a setting though:

pylintUseMinimalCheckers

You can set it to false and the arguments you mentioned won't be passed to pylint.

MikhailArkhipov pushed a commit that referenced this issue Feb 16, 2018
* Basic tokenizer

* Fixed property names

* Tests, round I

* Tests, round II

* tokenizer test

* Remove temorary change

* Fix merge issue

* Merge conflict

* Merge conflict

* Completion test

* Fix last line

* Fix javascript math

* Make test await for results

* Add license headers

* Rename definitions to types

* License headers

* Fix typo in completion details (typo)

* Fix hover test

* Russian translations

* Update to better translation

* Fix typo

*  #70 How to get all parameter info when filling in a function param list

* Fix #70 How to get all parameter info when filling in a function param list

* Clean up

* Clean imports

* CR feedback

* Trim whitespace for test stability

* More tests

* Better handle no-parameters documentation

* Better handle ellipsis and Python3

* #385 Auto-Indentation doesn't work after comment

* #141 Auto indentation broken when return keyword involved

* Undo changes

* #627 Docstrings for builtin methods are not parsed correctly

* reStructuredText converter

* Fix: period is not an operator

* Minor fixes

* Restructure

* Tests

* Tests

* Code heuristics

* Baselines

* HTML handling

* Lists

* State machine

* Baselines

* Squash

* no message

* Whitespace difference

* Update Jedi to 0.11.1

* Enable Travis

* Test fixes

* Undo change

* Jedi 0.11 with parser

* Undo changes

* Undo changes

* Test fixes

* Re-lint when interpreter changes

* Re-lint on linter config change

* Run linting command

* Encapsulate jupiter

* Handle promise

* More tests

* Tests

* Use service

* Linter provider tests

* Move methods to documents manager
@MikhailArkhipov
Copy link

18be595 further improves this

@robhaswell
Copy link

I'm pretty sure the old behaviour was to use the workspace .pylintrc? If not, is that possible somehow? Personally I don't care what is/isn't highlighted, as long as it is exactly equal to the things which are going to fail the linting step in my CI pipeline.

@patrys
Copy link

patrys commented Feb 16, 2018

@robhaswell See #788, it seems to be a bug.

@adgedenkers
Copy link

Forgive me, but is this resolved? I see the labels "closed-verified fixed" and "closed-fixed" had been added. Can you explain how you go about resolving this issue?

@noonedeadpunk
Copy link
Author

noonedeadpunk commented Feb 28, 2018

@adgedenkers It's actually pylint bug and is caused by -E flag (pylint-dev/pylint#1869).

But vscode-python has changed the way to launch pylint since the update "by design". In order to get old way of pylint you may set "python.linting.pylintUseMinimalCheckers": false for the vscode user-space settings.

@crazydogen
Copy link

crazydogen commented Mar 1, 2018

why not just disable the E1601 errors in settings?

{
    "python.linting.pylintArgs":
   [
        "–disable-msg=E1601"
   ]
}

@brettcannon
Copy link
Member

It's looking like Pylint won't be fixing this before our next release, so we will probably have to add an explicit disablement of that checker.

@brettcannon
Copy link
Member

If people want to help us test our fix, please install the insiders build of the extension and make sure you have Pylint 1.8 installed.

@brettcannon
Copy link
Member

I'm re-opening the issue as you get an extraneous error from Pylint about --disable=print-statement not being a module ATM.

@brettcannon brettcannon reopened this Mar 6, 2018
@brettcannon
Copy link
Member

In case we have to list every E error code manually to avoid enabling --py3k checkers:

E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701

You will notice that E1601 is not on there. This was created using https://gist.github.com/brettcannon/eff7f38a60af48d39814cbb2f33b3d1d .

@MatthieuScarset
Copy link

So... is the only solution to have a .pylintrc file in all our project?

I've tried the custom setting but it's not working.
#722 (comment)

@robhaswell
Copy link

So... is the only solution to have a .pylintrc file in all our project?

I think this is a good thing @MatthieuScarset. It's no different to other per-project configuration being present (e.g. .gitignore) and it means that the feedback in VS Code will match up with the results of running pylint from the command-line.

The only problem is that this doesn't work as of the latest release.

@brettcannon
Copy link
Member

@MatthieuScarset @robhaswell We have some fixes rolling out in the next release to strengthen our detection of custom settings and thus turning off our simpler rules. And as for this specific problem, we are literally meeting about this specific bug in less than an hour to come up with a solution (if we can), so we just ask people be patient as we are actively working on this and aiming to release this week (assuming no more showstopping bugs crop up 😉 ).

brettcannon added a commit to brettcannon/vscode-python that referenced this issue Mar 7, 2018
Due to a bug in Pylint where specifying `E` as enabled checks flips on `--py3k`, we need to explicitly list all `E` checkers to explicitly avoid (at least) print-statement which throws false-positives for folks not porting to Python 3.

Closes microsoft#722 by partially reverting microsoft#954
@brettcannon brettcannon self-assigned this Mar 7, 2018
brettcannon added a commit that referenced this issue Mar 7, 2018
Due to a bug in Pylint where specifying `E` as enabled checks flips on `--py3k`, we need to explicitly list all `E` checkers to explicitly avoid (at least) print-statement which throws false-positives for folks not porting to Python 3.

Closes #722 by partially reverting #954
@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-linting bug Issue identified by VS Code Team member as probable bug
Projects
None yet