You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recognize all symbols named TYPE_CHECKING for in_type_checking_block (#15719)
Closes#15681
## Summary
This changes `analyze::typing::is_type_checking_block` to recognize all
symbols named "TYPE_CHECKING".
This matches the current behavior of mypy and pyright as well as
`flake8-type-checking`.
It also drops support for detecting `if False:` and `if 0:` as type
checking blocks. This used to be an option for
providing backwards compatibility with Python versions that did not have
a `typing` module, but has since
been removed from the typing spec and is no longer supported by any of
the mainstream type checkers.
## Test Plan
`cargo nextest run`
---------
Co-authored-by: Micha Reiser <[email protected]>
Copy file name to clipboardExpand all lines: crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM108_SIM108.py.snap
+27
Original file line number
Diff line number
Diff line change
@@ -226,6 +226,33 @@ SIM108.py:167:1: SIM108 [*] Use ternary operator `z = 1 if True else other` inst
226
226
172169|ifFalse:
227
227
173170|z=1
228
228
229
+
SIM108.py:172:1: SIM108 [*] Useternaryoperator`z = 1 if False else other`insteadof`if`-`else`-block
230
+
|
231
+
170|z=other
232
+
171|
233
+
172|/ifFalse:
234
+
173||z=1
235
+
174||else:
236
+
175||z=other
237
+
||_____________^SIM108
238
+
176|
239
+
177|if1:
240
+
|
241
+
=help: Replace`if`-`else`-blockwith`z = 1 if False else other`
242
+
243
+
ℹ Unsafefix
244
+
169169|else:
245
+
170170|z=other
246
+
171171|
247
+
172|-ifFalse:
248
+
173|-z=1
249
+
174|-else:
250
+
175|-z=other
251
+
172|+z=1ifFalseelseother
252
+
176173|
253
+
177174|if1:
254
+
178175|z=True
255
+
229
256
SIM108.py:177:1: SIM108 [*] Useternaryoperator`z = True if 1 else other`insteadof`if`-`else`-block
0 commit comments