Skip to content

Commit

Permalink
Fix py3k (#3210)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hugues-aff authored and PCManticore committed Nov 4, 2019
1 parent 96b3892 commit 481be93
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,6 @@ contributors:
* laike9m: contributor

* Janne Rönkkö: contributor

* Hugues Bruant: contributor

4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Release date: TBA

* Python 3 porting mode is 30-50% faster on most codebases

* Python 3 porting mode no longer swallows syntax errors

Closes #2956


What's New in Pylint 2.4.3?
===========================
Expand Down
5 changes: 5 additions & 0 deletions pylint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@ def error_mode(self):
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("fatal") # F0001
self.enable("astroid-error") # F0002
self.enable("parse-error") # F0010
self.enable("syntax-error") # E0001
self.enable("python3")
if self._error_mode:
# The error mode was activated, using the -E flag.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ def test_py3k_option(self):
# Test that --py3k flag works.
rc_code = 0
self._runtest(
[join(HERE, "functional", "u", "unpacked_exceptions.py"), "--py3k"],
[join(HERE, "functional", "u", "unnecessary_lambda.py"), "--py3k"],
code=rc_code,
)

def test_py3k_jobs_option(self):
rc_code = 0
self._runtest(
[join(HERE, "functional", "u", "unpacked_exceptions.py"), "--py3k", "-j 2"],
[join(HERE, "functional", "u", "unnecessary_lambda.py"), "--py3k", "-j 2"],
code=rc_code,
)

Expand Down

0 comments on commit 481be93

Please sign in to comment.