Skip to content

Commit b33437f

Browse files
JBKahnJoseph Kahn
and
Joseph Kahn
authored
update namespace and remove python2 specific code (#55)
* update namespace and remove python2 specific code * remove extra space Co-authored-by: Joseph Kahn <[email protected]>
1 parent e405dd6 commit b33437f

File tree

7 files changed

+222
-287
lines changed

7 files changed

+222
-287
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: python
22
python:
3-
- "3.6"
43
- "3.7"
54
- "3.8"
65
- "3.9"
6+
- "3.10"
77

88
env:
99
matrix:

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,28 @@ Flake8 allows disabling some tests based on the folder:
2929
```
3030
[flake8]
3131
per-file-ignores =
32-
scripts/*: T00
33-
cli.py: T00
32+
scripts/*: T20
33+
cli.py: T20
3434
```
3535

36-
3736
Error codes
3837
-----------
3938

4039
| Error Code | Description |
4140
| ----------- | ------------------------------------ |
42-
| T001 | print found |
43-
| T002 | Python 2.x reserved word print used |
44-
| T003 | pprint found |
45-
| T004 | pprint declared |
41+
| T201 | print found |
42+
| T203 | pprint found |
43+
| T204 | pprint declared |
4644

4745

4846
Changes
4947
-------
5048

49+
##### 5.0.0 - 2022-04-30
50+
51+
* Move namespace from T0* to T2* to avoid collision with other library using same error code.
52+
* Remove python 2 specific code paths, error messages and six usage.
53+
5154
##### 4.0.1 - 2022-04-30
5255

5356
* Fixing bug with noqa detection by removing manual detection and relying on flake8 itself.

flake8_print.py

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
"""Extension for flake8 that finds usage of print."""
22
import pycodestyle
33
import ast
4-
from six import PY2, PY3
54

65
try:
76
from flake8.engine import pep8 as stdin_utils
87
except ImportError:
98
from flake8 import utils as stdin_utils
109

11-
__version__ = "4.0.0"
10+
__version__ = "5.0.0"
1211

1312
PRINT_FUNCTION_NAME = "print"
1413
PPRINT_FUNCTION_NAME = "pprint"
1514
PRINT_FUNCTION_NAMES = [PRINT_FUNCTION_NAME, PPRINT_FUNCTION_NAME]
1615

1716
VIOLATIONS = {
18-
"found": {"print": "T001 print found.", "pprint": "T003 pprint found."},
19-
"declared": {"print": "T002 Python 2.x reserved word print used.", "pprint": "T004 pprint declared"},
17+
"found": {"print": "T201 print found.", "pprint": "T203 pprint found."},
18+
"declared": {"print": "T202 Python 2.x reserved word print used.", "pprint": "T204 pprint declared"},
2019
}
2120

2221

@@ -26,10 +25,6 @@ def __init__(self, *args, **kwargs):
2625
self.prints_used = {}
2726
self.prints_redefined = {}
2827

29-
def visit_Print(self, node):
30-
"""Only exists in python 2."""
31-
self.prints_used[(node.lineno, node.col_offset)] = VIOLATIONS["found"][PRINT_FUNCTION_NAME]
32-
3328
def visit_Call(self, node):
3429
is_print_function = getattr(node.func, "id", None) in PRINT_FUNCTION_NAMES
3530
is_print_function_attribute = (
@@ -45,18 +40,14 @@ def visit_Call(self, node):
4540
def visit_FunctionDef(self, node):
4641
if node.name in PRINT_FUNCTION_NAMES:
4742
self.prints_redefined[(node.lineno, node.col_offset)] = VIOLATIONS["declared"][node.name]
48-
if PY2:
49-
for arg in node.args.args:
50-
if arg.id in PRINT_FUNCTION_NAMES:
51-
self.prints_redefined[(node.lineno, node.col_offset)] = VIOLATIONS["declared"][arg.id]
52-
elif PY3:
53-
for arg in node.args.args:
54-
if arg.arg in PRINT_FUNCTION_NAMES:
55-
self.prints_redefined[(node.lineno, node.col_offset)] = VIOLATIONS["declared"][arg.arg]
56-
57-
for arg in node.args.kwonlyargs:
58-
if arg.arg in PRINT_FUNCTION_NAMES:
59-
self.prints_redefined[(node.lineno, node.col_offset)] = VIOLATIONS["declared"][arg.arg]
43+
44+
for arg in node.args.args:
45+
if arg.arg in PRINT_FUNCTION_NAMES:
46+
self.prints_redefined[(node.lineno, node.col_offset)] = VIOLATIONS["declared"][arg.arg]
47+
48+
for arg in node.args.kwonlyargs:
49+
if arg.arg in PRINT_FUNCTION_NAMES:
50+
self.prints_redefined[(node.lineno, node.col_offset)] = VIOLATIONS["declared"][arg.arg]
6051
self.generic_visit(node)
6152

6253
def visit_Name(self, node):

0 commit comments

Comments
 (0)