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

no output for --py3k checker with python3 env #2956

Closed
rednaks opened this issue Jun 14, 2019 · 4 comments · Fixed by #3210
Closed

no output for --py3k checker with python3 env #2956

rednaks opened this issue Jun 14, 2019 · 4 comments · Fixed by #3210
Labels
Astroid Related to astroid Enhancement ✨ Improvement to a component

Comments

@rednaks
Copy link

rednaks commented Jun 14, 2019

Hello,

I'm testing pylint --py3k with a python 3 env (Python 3.5.2) with a basic file but the command is not returning any output:

PS. Python 3.5.2 is the default version on ubuntu xenial.

print "hello"


try:
    pass
except Exception, e:
    pass


a = xrange(10**8)

Version

pylint --version
pylint 2.3.1
astroid 2.2.5
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609]

with a python 2 (and pylint 1.9.4, astroid 1.6.6) it's working well, except for the exception syntax. (which is already mentioned in #2582)

I understand that two different pylint version for two different python versions, but are they maintained separately ? if yes, why ?

Thanks !

@justinfx
Copy link

justinfx commented Jun 19, 2019

We just discovered this as well, and I am wondering why the syntax errors aren't reported during --py3k. This happens as far back as pylint 1.6.4 on python2.7 and on pylint 2.3.1 with python3. I would think part of a py3k check would be to catch syntax errors. But there doesn't seem to be a way to even force it to catch them: pylint --py3k -e E0001

@PCManticore
Copy link
Contributor

This happens mainly because we use the Python 3's parser module for parsing this Python 2 file. Given you have Python 2 specific syntax, the parser fails to parse the file, resulting in syntax-error not being emitted when you have the --py3k mode enabled.

Ideally we should use a Python 2 specific parser, which we can actually expose via the typed_ast module that we use internally: https://github.com/PyCQA/astroid/blob/master/astroid/_ast.py#L26

Regarding your question on two versions of pylint, the issue is that Pylint 2.X is incompatible in terms of code changes with Pylint 1.9.X. The former works only for Python <3.7 and Python 2.7, and will be unsupported starting from 2020.

@PCManticore PCManticore added Astroid Related to astroid Enhancement ✨ Improvement to a component labels Jun 20, 2019
@rednaks
Copy link
Author

rednaks commented Jun 20, 2019

Alright, that makes sense now, thank you for your answer, I'll try to work on it, and I'll PR when I have a patch :)

@huguesb
Copy link

huguesb commented Oct 10, 2019

At the very least, pylint should report parse errors properly in py3k mode, which is easily done with this patch:

diff --git a/pylint/lint.py b/pylint/lint.py
index bbb01d35..dd651b5d 100644
--- a/pylint/lint.py
+++ b/pylint/lint.py
@@ -804,6 +804,11 @@ class PyLinter(
     def python3_porting_mode(self):
         """Disable all other checkers and enable Python 3 warnings."""
         self.disable("all")
+        # re-enable some errors, or 'print', 'raise', 'async', 'await' will mistakenly lint fine
+        self.enable("F0001")
+        self.enable("F0002")
+        self.enable("F0010")
+        self.enable("E0001")
         self.enable("python3")
         if self._error_mode:
             # The error mode was activated, using the -E flag.

huguesb pushed a commit to huguesb/pylint that referenced this issue Oct 21, 2019
Enable syntax errors to properly surface invalid code in py3
porting mode, instead of silently swallowing them and giving
the incorrect impression that the code is valid for py3.

Fixes pylint-dev#2956
huguesb pushed a commit to huguesb/pylint that referenced this issue Oct 21, 2019
Enable syntax errors to properly surface invalid code in py3
porting mode, instead of silently swallowing them and giving
the incorrect impression that the code is valid for py3.

Closes pylint-dev#2956
@huguesb huguesb mentioned this issue Oct 21, 2019
huguesb pushed a commit to huguesb/pylint that referenced this issue Oct 21, 2019
Enable syntax errors to properly surface invalid code in py3
porting mode, instead of silently swallowing them and giving
the incorrect impression that the code is valid for py3.

Closes pylint-dev#2956
huguesb pushed a commit to huguesb/pylint that referenced this issue Nov 1, 2019
Enable syntax errors to properly surface invalid code in py3
porting mode, instead of silently swallowing them and giving
the incorrect impression that the code is valid for py3.

Closes pylint-dev#2956
huguesb pushed a commit to huguesb/pylint that referenced this issue Nov 1, 2019
Enable syntax errors to properly surface invalid code in py3
porting mode, instead of silently swallowing them and giving
the incorrect impression that the code is valid for py3.

Closes pylint-dev#2956
PCManticore pushed a commit that referenced this issue Nov 4, 2019
Enable syntax errors to properly surface invalid code in py3
porting mode, instead of silently swallowing them and giving
the incorrect impression that the code is valid for py3.

Closes #2956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants