Skip to content
Snippets Groups Projects
Commit 809a8705 authored by Ian Lee's avatar Ian Lee
Browse files

Make explicit error on print only emit if "print_function" is imported; issue #338

parent 1fcf6008
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -575,7 +575,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
yield pos, "%s with same indent as next logical line" % code
 
 
def whitespace_before_parameters(logical_line, tokens):
def whitespace_before_parameters(logical_line, tokens, checker_state):
r"""Avoid extraneous whitespace.
 
Avoid extraneous whitespace in the following situations:
Loading
Loading
@@ -589,7 +589,6 @@ def whitespace_before_parameters(logical_line, tokens):
 
Okay: spam(1)
E211: spam (1)
E211: print (1)
 
Okay: dict['key'] = list[index]
E211: dict ['key'] = list[index]
Loading
Loading
@@ -597,6 +596,9 @@ def whitespace_before_parameters(logical_line, tokens):
"""
explicit_error = ('print',)
prev_type, prev_text, __, prev_end, __ = tokens[0]
if 'from __future__ import print_function' in logical_line:
checker_state['print_function'] = True
for index in range(1, len(tokens)):
token_type, text, start, end, __ = tokens[index]
if (token_type == tokenize.OP and
Loading
Loading
@@ -605,9 +607,10 @@ def whitespace_before_parameters(logical_line, tokens):
(prev_type == tokenize.NAME or prev_text in '}])') and
# Syntax "class A (B):" is allowed, but avoid it
(index < 2 or tokens[index - 2][1] != 'class') and
# Allow "return (a.foo for a in range(5))"
(not keyword.iskeyword(prev_text) or
prev_text in explicit_error)):
# Allow "return (a.foo for a in range(5))"
(not keyword.iskeyword(prev_text) or
(prev_text in explicit_error and
not checker_state.get('print_function')))):
yield prev_end, "E211 whitespace before '%s'" % text
prev_type = token_type
prev_text = text
Loading
Loading
Loading
Loading
@@ -7,6 +7,13 @@ dict['key'] ['subkey'] = list[index]
#: Okay
spam(1)
dict['key'] = list[index]
#: E211
print ('abc')
#: Okay
print('abc')
#: Okay
from __future__ import print_function
print ('abc')
 
 
# This is not prohibited by PEP8, but avoid it.
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment