mirror of
https://github.com/davidhalter/parso.git
synced 2026-02-24 18:51:03 +08:00
Proper handling of E251 / E252.
This commit is contained in:
@@ -15,9 +15,10 @@ _CLOSING_BRACKETS = ')', ']', '}'
|
|||||||
_FACTOR = '+', '-', '~'
|
_FACTOR = '+', '-', '~'
|
||||||
_ALLOW_SPACE = '*', '+', '-', '**', '/', '//', '@'
|
_ALLOW_SPACE = '*', '+', '-', '**', '/', '//', '@'
|
||||||
_BITWISE_OPERATOR = '<<', '>>', '|', '&', '^'
|
_BITWISE_OPERATOR = '<<', '>>', '|', '&', '^'
|
||||||
_NEEDS_SPACE = '=', '<', '>', '==', '>=', '<=', '<>', '!=', '%', \
|
_NEEDS_SPACE = ('=', '%', '->',
|
||||||
'+=', '-=', '*=', '@=', '/=', '%=', '&=', '|=', '^=', '<<=', \
|
'<', '>', '==', '>=', '<=', '<>', '!=',
|
||||||
'>>=', '**=', '//='
|
'+=', '-=', '*=', '@=', '/=', '%=', '&=', '|=', '^=', '<<=',
|
||||||
|
'>>=', '**=', '//=')
|
||||||
_NEEDS_SPACE += _BITWISE_OPERATOR
|
_NEEDS_SPACE += _BITWISE_OPERATOR
|
||||||
_IMPLICIT_INDENTATION_TYPES = ('dictorsetmaker', 'argument')
|
_IMPLICIT_INDENTATION_TYPES = ('dictorsetmaker', 'argument')
|
||||||
|
|
||||||
@@ -476,10 +477,6 @@ class PEP8Normalizer(Normalizer):
|
|||||||
elif leaf == ':': # Is a subscript
|
elif leaf == ':': # Is a subscript
|
||||||
# TODO
|
# TODO
|
||||||
pass
|
pass
|
||||||
elif prev.type == 'keyword':
|
|
||||||
add_not_spaces(275, 'Missing whitespace around keyword', info.indentation_part)
|
|
||||||
elif leaf.type == 'keyword':
|
|
||||||
add_not_spaces(275, 'Missing whitespace around keyword', info.indentation_part)
|
|
||||||
elif prev in (',', ';', ':'):
|
elif prev in (',', ';', ':'):
|
||||||
# TODO
|
# TODO
|
||||||
pass
|
pass
|
||||||
@@ -493,7 +490,14 @@ class PEP8Normalizer(Normalizer):
|
|||||||
elif leaf in _NEEDS_SPACE or prev in _NEEDS_SPACE:
|
elif leaf in _NEEDS_SPACE or prev in _NEEDS_SPACE:
|
||||||
if leaf == '=' and leaf.parent.type in ('argument', 'param') \
|
if leaf == '=' and leaf.parent.type in ('argument', 'param') \
|
||||||
or prev == '=' and prev.parent.type in ('argument', 'param'):
|
or prev == '=' and prev.parent.type in ('argument', 'param'):
|
||||||
add_if_spaces(251, 'Unexpected spaces around keyword / parameter equals', info.indentation_part)
|
if leaf == '=':
|
||||||
|
param = leaf.parent
|
||||||
|
else:
|
||||||
|
param = prev.parent
|
||||||
|
if param.type == 'param' and param.annotation:
|
||||||
|
add_not_spaces(252, 'Expected spaces around annotation equals', info.indentation_part)
|
||||||
|
else:
|
||||||
|
add_if_spaces(251, 'Unexpected spaces around keyword / parameter equals', info.indentation_part)
|
||||||
elif leaf in _BITWISE_OPERATOR or prev in _BITWISE_OPERATOR:
|
elif leaf in _BITWISE_OPERATOR or prev in _BITWISE_OPERATOR:
|
||||||
add_not_spaces(227, 'Missing whitespace around bitwise or shift operator', info.indentation_part)
|
add_not_spaces(227, 'Missing whitespace around bitwise or shift operator', info.indentation_part)
|
||||||
elif leaf == '%' or prev == '%':
|
elif leaf == '%' or prev == '%':
|
||||||
@@ -502,6 +506,8 @@ class PEP8Normalizer(Normalizer):
|
|||||||
message_225 = 'Missing whitespace between tokens'
|
message_225 = 'Missing whitespace between tokens'
|
||||||
add_not_spaces(225, message_225, info.indentation_part)
|
add_not_spaces(225, message_225, info.indentation_part)
|
||||||
#print('x', leaf.start_pos, leaf, prev)
|
#print('x', leaf.start_pos, leaf, prev)
|
||||||
|
elif leaf.type =='keyword' or prev.type == 'keyword':
|
||||||
|
add_not_spaces(275, 'Missing whitespace around keyword', info.indentation_part)
|
||||||
else:
|
else:
|
||||||
prev_info = self._previous_whitespace_info
|
prev_info = self._previous_whitespace_info
|
||||||
message_225 = 'Missing whitespace between tokens'
|
message_225 = 'Missing whitespace between tokens'
|
||||||
|
|||||||
56
test/normalizer_issue_files/E25.py
Normal file
56
test/normalizer_issue_files/E25.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#: E251:11 E251:13
|
||||||
|
def foo(bar = False):
|
||||||
|
'''Test function with an error in declaration'''
|
||||||
|
pass
|
||||||
|
#: E251:8
|
||||||
|
foo(bar= True)
|
||||||
|
#: E251:7
|
||||||
|
foo(bar =True)
|
||||||
|
#: E251:7 E251:9
|
||||||
|
foo(bar = True)
|
||||||
|
#: E251:13
|
||||||
|
y = bar(root= "sdasd")
|
||||||
|
parser.add_argument('--long-option',
|
||||||
|
#: E135+1:20
|
||||||
|
default=
|
||||||
|
"/rather/long/filesystem/path/here/blah/blah/blah")
|
||||||
|
parser.add_argument('--long-option',
|
||||||
|
default=
|
||||||
|
"/rather/long/filesystem")
|
||||||
|
#: E999+1:44
|
||||||
|
parser.add_argument('--long-option', default
|
||||||
|
="/rather/long/filesystem/path/here/blah/blah/blah")
|
||||||
|
#: E251+2:7 E251+2:9
|
||||||
|
foo(True,
|
||||||
|
baz=(1, 2),
|
||||||
|
biz = 'foo'
|
||||||
|
)
|
||||||
|
# Okay
|
||||||
|
foo(bar=(1 == 1))
|
||||||
|
foo(bar=(1 != 1))
|
||||||
|
foo(bar=(1 >= 1))
|
||||||
|
foo(bar=(1 <= 1))
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
d[type(None)] = _deepcopy_atomic
|
||||||
|
|
||||||
|
# Annotated Function Definitions
|
||||||
|
# Okay
|
||||||
|
def munge(input: AnyStr, sep: AnyStr = None, limit=1000,
|
||||||
|
extra: Union[str, dict] = None) -> AnyStr:
|
||||||
|
pass
|
||||||
|
# Okay
|
||||||
|
async def add(a: int = 0, b: int = 0) -> int:
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
# Previously E251 four times
|
||||||
|
#: E221:5
|
||||||
|
async def add(a: int = 0, b: int = 0) -> int:
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
#: E225:24 E225:26
|
||||||
|
def x(b: tuple = (1, 2))->int:
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
#: E252:11 E252:12
|
||||||
|
def b(a:int=1):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user