@@ -1296,6 +1296,9 @@ def _break_around_binary_operators(tokens):
12961296 """
12971297 line_break = False
12981298 unary_context = True
1299+ param_name_context = False
1300+ # only counted when inside param list, `-1` when not counting
1301+ enclosure_count = - 1
12991302 # Previous non-newline token types and text
13001303 previous_token_type = None
13011304 previous_text = None
@@ -1306,11 +1309,30 @@ def _break_around_binary_operators(tokens):
13061309 line_break = True
13071310 else :
13081311 yield (token_type , text , previous_token_type , previous_text ,
1309- line_break , unary_context , start )
1312+ line_break , unary_context , param_name_context , start )
13101313 unary_context = text in '([{,;'
13111314 line_break = False
13121315 previous_token_type = token_type
13131316 previous_text = text
1317+ if enclosure_count != - 1 :
1318+ if token_type != tokenize .OP :
1319+ pass
1320+ elif text in '([{' :
1321+ enclosure_count += 1
1322+ elif text in ')]}' :
1323+ enclosure_count -= 1
1324+ if enclosure_count == 0 :
1325+ # stop counting enclosures
1326+ enclosure_count = - 1
1327+ elif token_type == tokenize .NAME and text == 'def' :
1328+ # start counting enclosures
1329+ enclosure_count = 0
1330+ # check for enclosure count and last token to make sure that
1331+ # only the actual positional-only marker matches here:
1332+ # def f(
1333+ # x=4/2, y=(1, 4/2), /
1334+ # ):
1335+ param_name_context = text == ',' and enclosure_count == 1
13141336
13151337
13161338@register_check
@@ -1335,9 +1357,10 @@ def break_before_binary_operator(logical_line, tokens):
13351357 """
13361358 for context in _break_around_binary_operators (tokens ):
13371359 (token_type , text , previous_token_type , previous_text ,
1338- line_break , unary_context , start ) = context
1360+ line_break , unary_context , param_name_context , start ) = context
13391361 if (_is_binary_operator (token_type , text ) and line_break and
13401362 not unary_context and
1363+ not param_name_context and
13411364 not _is_binary_operator (previous_token_type ,
13421365 previous_text )):
13431366 yield start , "W503 line break before binary operator"
@@ -1367,15 +1390,18 @@ def break_after_binary_operator(logical_line, tokens):
13671390 Okay: var = (1 +\n -1 +\n -2)
13681391 """
13691392 prev_start = None
1393+ prev_param_name_context = False
13701394 for context in _break_around_binary_operators (tokens ):
13711395 (token_type , text , previous_token_type , previous_text ,
1372- line_break , unary_context , start ) = context
1396+ line_break , unary_context , param_name_context , start ) = context
13731397 if (_is_binary_operator (previous_token_type , previous_text ) and
13741398 line_break and
13751399 not unary_context and
1400+ not prev_param_name_context and
13761401 not _is_binary_operator (token_type , text )):
13771402 yield prev_start , "W504 line break after binary operator"
13781403 prev_start = start
1404+ prev_param_name_context = param_name_context
13791405
13801406
13811407@register_check
0 commit comments