1
1
"""Extension for flake8 that finds usage of print."""
2
2
import pycodestyle
3
3
import ast
4
- from six import PY2 , PY3
5
4
6
5
try :
7
6
from flake8 .engine import pep8 as stdin_utils
8
7
except ImportError :
9
8
from flake8 import utils as stdin_utils
10
9
11
- __version__ = "4 .0.0"
10
+ __version__ = "5 .0.0"
12
11
13
12
PRINT_FUNCTION_NAME = "print"
14
13
PPRINT_FUNCTION_NAME = "pprint"
15
14
PRINT_FUNCTION_NAMES = [PRINT_FUNCTION_NAME , PPRINT_FUNCTION_NAME ]
16
15
17
16
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" },
20
19
}
21
20
22
21
@@ -26,10 +25,6 @@ def __init__(self, *args, **kwargs):
26
25
self .prints_used = {}
27
26
self .prints_redefined = {}
28
27
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
-
33
28
def visit_Call (self , node ):
34
29
is_print_function = getattr (node .func , "id" , None ) in PRINT_FUNCTION_NAMES
35
30
is_print_function_attribute = (
@@ -45,18 +40,14 @@ def visit_Call(self, node):
45
40
def visit_FunctionDef (self , node ):
46
41
if node .name in PRINT_FUNCTION_NAMES :
47
42
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 ]
60
51
self .generic_visit (node )
61
52
62
53
def visit_Name (self , node ):
0 commit comments