@@ -1184,16 +1184,15 @@ def break_before_binary_operator(logical_line, tokens):
11841184
11851185 W503: (width == 0\n + height == 0)
11861186 W503: (width == 0\n and height == 0)
1187+ W503: var = (1\n & ~2)
1188+ W503: var = (1\n / -2)
1189+ W503: var = (1\n + -1\n + -2)
11871190
1188- Okay: (width == 0 +\n height == 0)
11891191 Okay: foo(\n -x)
11901192 Okay: foo(x\n [])
11911193 Okay: x = '''\n''' + ''
11921194 Okay: foo(x,\n -y)
11931195 Okay: foo(x, # comment\n -y)
1194- Okay: var = (1 &\n ~2)
1195- Okay: var = (1 /\n -2)
1196- Okay: var = (1 +\n -1 +\n -2)
11971196 """
11981197 for context in _break_around_binary_operators (tokens ):
11991198 (token_type , text , previous_token_type , previous_text ,
@@ -1215,25 +1214,26 @@ def break_after_binary_operator(logical_line, tokens):
12151214
12161215 W504: (width == 0 +\n height == 0)
12171216 W504: (width == 0 and\n height == 0)
1217+ W504: var = (1 &\n ~2)
12181218
1219- Okay: (width == 0\n + height == 0)
12201219 Okay: foo(\n -x)
12211220 Okay: foo(x\n [])
12221221 Okay: x = '''\n''' + ''
12231222 Okay: x = '' + '''\n'''
12241223 Okay: foo(x,\n -y)
12251224 Okay: foo(x, # comment\n -y)
1226- Okay: var = (1\n & ~2)
1227- Okay: var = (1\n / -2)
1228- Okay: var = (1\n + -1\n + -2)
1225+
1226+ The following should be W504 but unary_context is tricky with these
1227+ Okay: var = (1 /\n -2)
1228+ Okay: var = (1 +\n -1 +\n -2)
12291229 """
12301230 for context in _break_around_binary_operators (tokens ):
12311231 (token_type , text , previous_token_type , previous_text ,
12321232 line_break , unary_context , start ) = context
1233- if (_is_binary_operator (previous_token_type , previous_text )
1234- and line_break
1235- and not unary_context
1236- and not _is_binary_operator (token_type , text )):
1233+ if (_is_binary_operator (previous_token_type , previous_text ) and
1234+ line_break and
1235+ not unary_context and
1236+ not _is_binary_operator (token_type , text )):
12371237 error_pos = (start [0 ] - 1 , start [1 ])
12381238 yield error_pos , "W504 line break after binary operator"
12391239
0 commit comments