Skip to content

print statement is highlighted by pylint #722

Closed

Description

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.

Activity

  1. MikhailArkhipov commented on Feb 7, 2018

    @MikhailArkhipov

    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.

  2. noonedeadpunk commented on Feb 7, 2018

    @noonedeadpunk
    Author

    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.

  3. zerkms commented on Feb 7, 2018

    @zerkms

    Dmitriy Rabotyagov (@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}'
    
  4. noonedeadpunk commented on Feb 7, 2018

    @noonedeadpunk
    Author

    Ivan Kurnosov (@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.

  5. zerkms commented on Feb 7, 2018

    @zerkms

    Dmitriy Rabotyagov (@noonedeadpunk) if you report it to the pylink could you please post a link here

  6. noonedeadpunk commented on Feb 7, 2018

    @noonedeadpunk
    Author

    Ivan Kurnosov (@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.

  7. zerkms commented on Feb 7, 2018

    @zerkms

    I personally use logger instead of print ;-)

  8. noonedeadpunk commented on Feb 8, 2018

    @noonedeadpunk
    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 Ivan Kurnosov (@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

  9. 17 remaining items

  10. brettcannon commented on Mar 3, 2018

    @brettcannon
    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.

  11. brettcannon commented on Mar 6, 2018

    @brettcannon
    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.

  12. brettcannon commented on Mar 6, 2018

    @brettcannon
    Member

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

  13. brettcannon commented on Mar 7, 2018

    @brettcannon
    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://github.com/proxy/gist.github.com/brettcannon/eff7f38a60af48d39814cbb2f33b3d1d .

  14. MatthieuScarset commented on Mar 7, 2018

    @MatthieuScarset

    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)

  15. robhaswell commented on Mar 7, 2018

    @robhaswell

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

    I think this is a good thing MattGyver (@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.

  16. brettcannon commented on Mar 7, 2018

    @brettcannon
    Member

    MattGyver (@MatthieuScarset) Rob Haswell (@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 😉 ).

  17. added a commit that references this issue on Mar 7, 2018
    610a95f
  18. added a commit that references this issue on Mar 7, 2018
    dae0541
  19. locked as resolved and limited conversation to collaborators on Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-lintingbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions