@@ -323,7 +323,7 @@ RUF056.py:149:32: RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in
323323 149 | + value = not my_dict .get (" key" ) # [RUF056 ]
324324150 150 | value = not my_dict .get (" key" , " " ) # [RUF056 ]
325325151 151 |
326- 152 152 | # testing dict .get call using kwargs
326+ 152 152 | # testing invalid dict .get call with inline comment
327327
328328RUF056 .py :150 :32 : RUF056 [* ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
329329 |
@@ -332,7 +332,7 @@ RUF056.py:150:32: RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in
332332150 | value = not my_dict .get (" key" , " " ) # [RUF056 ]
333333 | ^^ RUF056
334334151 |
335- 152 | # testing dict .get call using kwargs
335+ 152 | # testing invalid dict .get call with inline comment
336336 |
337337 = help : Remove falsy fallback from ` dict.get()`
338338
@@ -343,142 +343,131 @@ RUF056.py:150:32: RUF056 [*] Avoid providing a falsy fallback to `dict.get()` in
343343150 | - value = not my_dict .get (" key" , " " ) # [RUF056 ]
344344 150 | + value = not my_dict .get (" key" ) # [RUF056 ]
345345151 151 |
346- 152 152 | # testing dict .get call using kwargs
347- 153 153 | value = not my_dict .get (key = " key" , default = False ) # [ RUF056 ]
346+ 152 152 | # testing invalid dict .get call with inline comment
347+ 153 153 | value = not my_dict .get (" key" , # comment1
348348
349- RUF056 .py :153 : 36 : RUF056 [* ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
349+ RUF056 .py :154 : 22 : RUF056 [* ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
350350 |
351- 152 | # testing dict .get call using kwargs
352- 153 | value = not my_dict .get (key = " key" , default = False ) # [RUF056 ]
353- | ^^^^^^^^^^^^^ RUF056
354- 154 | value = not my_dict .get (default = [], key = " key" ) # [RUF056 ]
351+ 152 | # testing invalid dict .get call with inline comment
352+ 153 | value = not my_dict .get (" key" , # comment1
353+ 154 | [] # comment2
354+ | ^^ RUF056
355+ 155 | ) # [RUF056 ]
355356 |
356357 = help : Remove falsy fallback from ` dict.get()`
357358
358- ℹ Safe fix
359+ ℹ Unsafe fix
359360150 150 | value = not my_dict .get (" key" , " " ) # [RUF056 ]
360361151 151 |
361- 152 152 | # testing dict .get call using kwargs
362- 153 | - value = not my_dict .get (key = " key" , default = False ) # [ RUF056 ]
363- 153 | + value = not my_dict . get ( key = " key " ) # [ RUF056 ]
364- 154 154 | value = not my_dict .get (default = [], key = " key" ) # [ RUF056 ]
365- 155 155 |
366- 156 156 | # testing invalid dict . get call with inline comment
367-
368- RUF056 . py : 154 : 25 : RUF056 [ * ] Avoid providing a falsy fallback to ` dict.get() ` in boolean test positions . The default fallback ` None ` is already falsy .
369- |
370- 152 | # testing dict . get call using kwargs
371- 153 | value = not my_dict . get ( key = " key " , default = False ) # [ RUF056 ]
372- 154 | value = not my_dict .get (default = [], key = " key" ) # [ RUF056 ]
373- | ^^^^^ ^^^^^ RUF056
374- 155 |
375- 156 | # testing invalid dict . get call with inline comment
362+ 152 152 | # testing invalid dict .get call with inline comment
363+ 153 | - value = not my_dict .get (" key" , # comment1
364+ 154 | - [] # comment2
365+ 153 | + value = not my_dict .get (" key" # comment2
366+ 155 154 | ) # [ RUF056 ]
367+ 156 155 |
368+ 157 156 | # regression tests for https : // github.com/astral-sh/ruff/issues/18628
369+
370+ RUF056 . py : 163 : 24 : RUF056 Avoid providing a falsy fallback to ` dict.get() ` in boolean test positions . The default fallback ` None ` is already falsy .
371+ |
372+ 162 | # extra positional
373+ 163 | not my_dict .get (" key" , False , " ?! " )
374+ | ^^^^^ RUF056
375+ 164 |
376+ 165 | # ` default ` is positional - only , so these are invalid
376377 |
377378 = help : Remove falsy fallback from ` dict.get()`
378379
379- ℹ Safe fix
380- 151 151 |
381- 152 152 | # testing dict .get call using kwargs
382- 153 153 | value = not my_dict .get (key = " key" , default = False ) # [RUF056 ]
383- 154 | - value = not my_dict .get (default = [], key = " key" ) # [RUF056 ]
384- 154 | + value = not my_dict .get (key = " key" ) # [RUF056 ]
385- 155 155 |
386- 156 156 | # testing invalid dict .get call with inline comment
387- 157 157 | value = not my_dict .get (" key" , # comment1
388-
389- RUF056 .py :158 :22 : RUF056 [* ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
390- |
391- 156 | # testing invalid dict .get call with inline comment
392- 157 | value = not my_dict .get (" key" , # comment1
393- 158 | [] # comment2
394- | ^^ RUF056
395- 159 | ) # [RUF056 ]
380+ RUF056 .py :166 :24 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
381+ |
382+ 165 | # ` default` is positional - only , so these are invalid
383+ 166 | not my_dict .get (" key" , default = False )
384+ | ^^^^^^^^^^^^^ RUF056
385+ 167 | not my_dict .get (key = " key" , default = False )
386+ 168 | not my_dict .get (default = [], key = " key" )
396387 |
397388 = help : Remove falsy fallback from ` dict.get()`
398389
399- ℹ Unsafe fix
400- 154 154 | value = not my_dict .get (default = [], key = " key" ) # [RUF056 ]
401- 155 155 |
402- 156 156 | # testing invalid dict .get call with inline comment
403- 157 | - value = not my_dict .get (" key" , # comment1
404- 158 | - [] # comment2
405- 157 | + value = not my_dict .get (" key" # comment2
406- 159 158 | ) # [RUF056 ]
407- 160 159 |
408- 161 160 | # testing invalid dict .get call with kwargs and inline comment
409-
410- RUF056 .py :163 :25 : RUF056 [* ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
411- |
412- 161 | # testing invalid dict .get call with kwargs and inline comment
413- 162 | value = not my_dict .get (key = " key" , # comment1
414- 163 | default = False # comment2
415- | ^^^^^^^^^^^^^ RUF056
416- 164 | ) # [RUF056 ]
417- 165 | value = not my_dict .get (default = [], # comment1
390+ RUF056 .py :167 :28 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
391+ |
392+ 165 | # ` default` is positional - only , so these are invalid
393+ 166 | not my_dict .get (" key" , default = False )
394+ 167 | not my_dict .get (key = " key" , default = False )
395+ | ^^^^^^^^^^^^^ RUF056
396+ 168 | not my_dict .get (default = [], key = " key" )
397+ 169 | not my_dict .get (default = False )
418398 |
419399 = help : Remove falsy fallback from ` dict.get()`
420400
421- ℹ Unsafe fix
422- 159 159 | ) # [RUF056 ]
423- 160 160 |
424- 161 161 | # testing invalid dict .get call with kwargs and inline comment
425- 162 | - value = not my_dict .get (key = " key" , # comment1
426- 163 | - default = False # comment2
427- 162 | + value = not my_dict .get (key = " key" # comment2
428- 164 163 | ) # [RUF056 ]
429- 165 164 | value = not my_dict .get (default = [], # comment1
430- 166 165 | key = " key" # comment2
431-
432- RUF056 .py :165 :25 : RUF056 [* ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
433- |
434- 163 | default = False # comment2
435- 164 | ) # [RUF056 ]
436- 165 | value = not my_dict .get (default = [], # comment1
437- | ^^^^^^^^^^ RUF056
438- 166 | key = " key" # comment2
439- 167 | ) # [RUF056 ]
401+ RUF056 .py :168 :17 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
402+ |
403+ 166 | not my_dict .get (" key" , default = False )
404+ 167 | not my_dict .get (key = " key" , default = False )
405+ 168 | not my_dict .get (default = [], key = " key" )
406+ | ^^^^^^^^^^ RUF056
407+ 169 | not my_dict .get (default = False )
408+ 170 | not my_dict .get (key = " key" , other = " something" , default = False )
440409 |
441410 = help : Remove falsy fallback from ` dict.get()`
442411
443- ℹ Unsafe fix
444- 162 162 | value = not my_dict .get (key = " key" , # comment1
445- 163 163 | default = False # comment2
446- 164 164 | ) # [RUF056 ]
447- 165 | - value = not my_dict .get (default = [], # comment1
448- 165 | + value = not my_dict .get (# comment1
449- 166 166 | key = " key" # comment2
450- 167 167 | ) # [RUF056 ]
451- 168 168 |
452-
453- RUF056 .py :170 :55 : RUF056 [* ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
454- |
455- 169 | # testing invalid dict .get calls
456- 170 | value = not my_dict .get (key = " key" , other = " something" , default = False )
457- | ^^^^^^^^^^^^^ RUF056
458- 171 | value = not my_dict .get (default = False , other = " something" , key = " test" )
412+ RUF056 .py :169 :17 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
413+ |
414+ 167 | not my_dict .get (key = " key" , default = False )
415+ 168 | not my_dict .get (default = [], key = " key" )
416+ 169 | not my_dict .get (default = False )
417+ | ^^^^^^^^^^^^^ RUF056
418+ 170 | not my_dict .get (key = " key" , other = " something" , default = False )
419+ 171 | not my_dict .get (default = False , other = " something" , key = " test" )
459420 |
460421 = help : Remove falsy fallback from ` dict.get()`
461422
462- ℹ Safe fix
463- 167 167 | ) # [RUF056 ]
464- 168 168 |
465- 169 169 | # testing invalid dict .get calls
466- 170 | - value = not my_dict .get (key = " key" , other = " something" , default = False )
467- 170 | + value = not my_dict .get (key = " key" , other = " something" )
468- 171 171 | value = not my_dict .get (default = False , other = " something" , key = " test" )
423+ RUF056 .py :170 :47 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
424+ |
425+ 168 | not my_dict .get (default = [], key = " key" )
426+ 169 | not my_dict .get (default = False )
427+ 170 | not my_dict .get (key = " key" , other = " something" , default = False )
428+ | ^^^^^^^^^^^^^ RUF056
429+ 171 | not my_dict .get (default = False , other = " something" , key = " test" )
430+ |
431+ = help : Remove falsy fallback from ` dict.get()`
469432
470- RUF056 .py :171 :25 : RUF056 [ * ] Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
433+ RUF056 .py :171 :17 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
471434 |
472- 169 | # testing invalid dict .get calls
473- 170 | value = not my_dict .get (key = " key" , other = " something" , default = False )
474- 171 | value = not my_dict .get (default = False , other = " something" , key = " test" )
475- | ^^^^^^^^^^^^^ RUF056
435+ 169 | not my_dict .get (default = False )
436+ 170 | not my_dict .get (key = " key" , other = " something" , default = False )
437+ 171 | not my_dict .get (default = False , other = " something" , key = " test" )
438+ | ^^^^^^^^^^^^^ RUF056
439+ 172 |
440+ 173 | # comments don ' t really matter here because of the kwargs but include them for
476441 |
477442 = help : Remove falsy fallback from ` dict.get()`
478443
479- ℹ Safe fix
480- 168 168 |
481- 169 169 | # testing invalid dict .get calls
482- 170 170 | value = not my_dict .get (key = " key" , other = " something" , default = False )
483- 171 | - value = not my_dict .get (default = False , other = " something" , key = " test" )
484- 171 | + value = not my_dict .get (other = " something" , key = " test" )
444+ RUF056 .py :177 :5 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
445+ |
446+ 175 | not my_dict .get (
447+ 176 | key = " key" , # comment1
448+ 177 | default = False , # comment2
449+ | ^^^^^^^^^^^^^ RUF056
450+ 178 | ) # comment 3
451+ 179 | not my_dict .get (
452+ |
453+ = help : Remove falsy fallback from ` dict.get()`
454+
455+ RUF056 .py :180 :5 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
456+ |
457+ 178 | ) # comment 3
458+ 179 | not my_dict .get (
459+ 180 | default = [], # comment1
460+ | ^^^^^^^^^^ RUF056
461+ 181 | key = " key" , # comment2
462+ 182 | ) # comment 3
463+ |
464+ = help : Remove falsy fallback from ` dict.get()`
465+
466+ RUF056 .py :187 :24 : RUF056 Avoid providing a falsy fallback to ` dict.get()` in boolean test positions . The default fallback ` None` is already falsy .
467+ |
468+ 185 | # TypeError is raised at runtime before and after the fix , but we still bail
469+ 186 | # out for having an unrecognized number of arguments
470+ 187 | not my_dict .get (" key" , False , foo = ... )
471+ | ^^^^^ RUF056
472+ |
473+ = help : Remove falsy fallback from ` dict.get()`
0 commit comments