---
source: crates/ruff/src/rules/flake8_commas/mod.rs
---
COM81.py:4:18: COM812 [*] Trailing comma missing
  |
4 | bad_function_call(
5 |     param1='test',
6 |     param2='test'
  |                   COM812
7 | )
8 | # ==> bad_list.py <==
  |
  = help: Add trailing comma

ℹ Suggested fix
1 1 | # ==> bad_function_call.py <==
2 2 | bad_function_call(
3 3 |     param1='test',
4   |-    param2='test'
  4 |+    param2='test',
5 5 | )
6 6 | # ==> bad_list.py <==
7 7 | bad_list = [

COM81.py:10:6: COM812 [*] Trailing comma missing
   |
10 |     1,
11 |     2,
12 |     3
   |       COM812
13 | ]
   |
   = help: Add trailing comma

ℹ Suggested fix
7  7  | bad_list = [
8  8  |     1,
9  9  |     2,
10    |-    3
   10 |+    3,
11 11 | ]
12 12 | 
13 13 | bad_list_with_comment = [

COM81.py:16:6: COM812 [*] Trailing comma missing
   |
16 |     1,
17 |     2,
18 |     3
   |       COM812
19 |     # still needs a comma!
20 | ]
   |
   = help: Add trailing comma

ℹ Suggested fix
13 13 | bad_list_with_comment = [
14 14 |     1,
15 15 |     2,
16    |-    3
   16 |+    3,
17 17 |     # still needs a comma!
18 18 | ]
19 19 | 

COM81.py:23:6: COM812 [*] Trailing comma missing
   |
23 |     1,
24 |     2,
25 |     3
   |       COM812
   |
   = help: Add trailing comma

ℹ Suggested fix
20 20 | bad_list_with_extra_empty = [
21 21 |     1,
22 22 |     2,
23    |-    3
   23 |+    3,
24 24 | 
25 25 | 
26 26 | 

COM81.py:36:8: COM818 Trailing comma on bare tuple prohibited
   |
36 | foo = (1,)
37 | 
38 | foo = 1,
   |        ^ COM818
39 | 
40 | bar = 1; foo = bar,
   |

COM81.py:38:19: COM818 Trailing comma on bare tuple prohibited
   |
38 | foo = 1,
39 | 
40 | bar = 1; foo = bar,
   |                   ^ COM818
41 | 
42 | foo = (
   |

COM81.py:45:8: COM818 Trailing comma on bare tuple prohibited
   |
45 | )
46 | 
47 | foo = 3, 
   |        ^ COM818
48 | 
49 | class A(object):
   |

COM81.py:49:10: COM818 Trailing comma on bare tuple prohibited
   |
49 | class A(object):
50 |  foo = 3
51 |  bar = 10,
   |          ^ COM818
52 |  foo_bar = 2
   |

COM81.py:56:32: COM818 Trailing comma on bare tuple prohibited
   |
56 | from foo import bar, baz
57 | 
58 | group_by = function_call('arg'),
   |                                ^ COM818
59 | 
60 | group_by = ('foobar' * 3),
   |

COM81.py:58:26: COM818 Trailing comma on bare tuple prohibited
   |
58 | group_by = function_call('arg'),
59 | 
60 | group_by = ('foobar' * 3),
   |                          ^ COM818
61 | 
62 | def foo():
   |

COM81.py:61:17: COM818 Trailing comma on bare tuple prohibited
   |
61 | def foo():
62 |     return False,
   |                 ^ COM818
63 | 
64 | # ==> callable_before_parenth_form.py <==
   |

COM81.py:70:8: COM812 [*] Trailing comma missing
   |
70 | {'foo': foo}['foo'](
71 |     bar
   |         COM812
72 | )
   |
   = help: Add trailing comma

ℹ Suggested fix
67 67 |     pass
68 68 | 
69 69 | {'foo': foo}['foo'](
70    |-    bar
   70 |+    bar,
71 71 | )
72 72 | 
73 73 | {'foo': foo}['foo'](

COM81.py:78:8: COM812 [*] Trailing comma missing
   |
78 | (foo)(
79 |     bar
   |         COM812
80 | )
   |
   = help: Add trailing comma

ℹ Suggested fix
75 75 | )
76 76 | 
77 77 | (foo)(
78    |-    bar
   78 |+    bar,
79 79 | )
80 80 | 
81 81 | (foo)[0](

COM81.py:86:8: COM812 [*] Trailing comma missing
   |
86 | [foo][0](
87 |     bar
   |         COM812
88 | )
   |
   = help: Add trailing comma

ℹ Suggested fix
83 83 | )
84 84 | 
85 85 | [foo][0](
86    |-    bar
   86 |+    bar,
87 87 | )
88 88 | 
89 89 | [foo][0](

COM81.py:152:6: COM812 [*] Trailing comma missing
    |
152 | # ==> keyword_before_parenth_form/base_bad.py <==
153 | from x import (
154 |     y
    |       COM812
155 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
149 149 | 
150 150 | # ==> keyword_before_parenth_form/base_bad.py <==
151 151 | from x import (
152     |-    y
    152 |+    y,
153 153 | )
154 154 | 
155 155 | assert(

COM81.py:158:11: COM812 [*] Trailing comma missing
    |
158 |     SyntaxWarning,
159 |     ThrownHere,
160 |     Anyway
    |            COM812
161 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
155 155 | assert(
156 156 |     SyntaxWarning,
157 157 |     ThrownHere,
158     |-    Anyway
    158 |+    Anyway,
159 159 | )
160 160 | 
161 161 | # async await is fine outside an async def

COM81.py:293:15: COM812 [*] Trailing comma missing
    |
293 | # ==> multiline_bad_dict.py <==
294 | multiline_bad_dict = {
295 |     "bad": 123
    |                COM812
296 | }
297 | # ==> multiline_bad_function_def.py <==
    |
    = help: Add trailing comma

ℹ Suggested fix
290 290 | 
291 291 | # ==> multiline_bad_dict.py <==
292 292 | multiline_bad_dict = {
293     |-    "bad": 123
    293 |+    "bad": 123,
294 294 | }
295 295 | # ==> multiline_bad_function_def.py <==
296 296 | def func_good(

COM81.py:304:14: COM812 [*] Trailing comma missing
    |
304 | def func_bad(
305 |         a = 3,
306 |         b = 2
    |               COM812
307 |     ):
308 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
301 301 | 
302 302 | def func_bad(
303 303 |         a = 3,
304     |-        b = 2
    304 |+        b = 2,
305 305 |     ):
306 306 |     pass
307 307 | 

COM81.py:310:14: COM812 [*] Trailing comma missing
    |
310 | # ==> multiline_bad_function_one_param.py <==
311 | def func(
312 |         a = 3
    |               COM812
313 |     ):
314 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
307 307 | 
308 308 | # ==> multiline_bad_function_one_param.py <==
309 309 | def func(
310     |-        a = 3
    310 |+        a = 3,
311 311 |     ):
312 312 |     pass
313 313 | 

COM81.py:316:10: COM812 [*] Trailing comma missing
    |
316 | func(
317 |     a = 3
    |           COM812
318 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
313 313 | 
314 314 | 
315 315 | func(
316     |-    a = 3
    316 |+    a = 3,
317 317 | )
318 318 | 
319 319 | # ==> multiline_bad_or_dict.py <==

COM81.py:322:15: COM812 [*] Trailing comma missing
    |
322 | multiline_bad_or_dict = {
323 |     "good": True or False,
324 |     "bad": 123
    |                COM812
325 | }
    |
    = help: Add trailing comma

ℹ Suggested fix
319 319 | # ==> multiline_bad_or_dict.py <==
320 320 | multiline_bad_or_dict = {
321 321 |     "good": True or False,
322     |-    "bad": 123
    322 |+    "bad": 123,
323 323 | }
324 324 | 
325 325 | # ==> multiline_good_dict.py <==

COM81.py:368:15: COM812 [*] Trailing comma missing
    |
368 | multiline_index_access[
369 |     "probably fine",
370 |     "not good"
    |                COM812
371 | ]
    |
    = help: Add trailing comma

ℹ Suggested fix
365 365 | 
366 366 | multiline_index_access[
367 367 |     "probably fine",
368     |-    "not good"
    368 |+    "not good",
369 369 | ]
370 370 | 
371 371 | multiline_index_access[

COM81.py:375:15: COM812 [*] Trailing comma missing
    |
375 |     "fine",
376 |     :
377 |     "not good"
    |                COM812
378 | ]
    |
    = help: Add trailing comma

ℹ Suggested fix
372 372 |     "fine",
373 373 |     "fine",
374 374 |     :
375     |-    "not good"
    375 |+    "not good",
376 376 | ]
377 377 | 
378 378 | # ==> multiline_string.py <==

COM81.py:404:15: COM812 [*] Trailing comma missing
    |
404 |     "fine"
405 |     :
406 |     "not fine"
    |                COM812
407 | ]
    |
    = help: Add trailing comma

ℹ Suggested fix
401 401 |     "fine",
402 402 |     "fine"
403 403 |     :
404     |-    "not fine"
    404 |+    "not fine",
405 405 | ]
406 406 | 
407 407 | multiline_index_access[

COM81.py:432:15: COM812 [*] Trailing comma missing
    |
432 |     :
433 |     "fine",
434 |     "not fine"
    |                COM812
435 | ]
    |
    = help: Add trailing comma

ℹ Suggested fix
429 429 |     "fine"
430 430 |     :
431 431 |     "fine",
432     |-    "not fine"
    432 |+    "not fine",
433 433 | ]
434 434 | 
435 435 | multiline_index_access[

COM81.py:485:21: COM819 [*] Trailing comma prohibited
    |
485 | # ==> prohibited.py <==
486 | foo = ['a', 'b', 'c',]
    |                     ^ COM819
487 | 
488 | bar = { a: b,}
    |
    = help: Remove trailing comma

ℹ Suggested fix
482 482 | )
483 483 | 
484 484 | # ==> prohibited.py <==
485     |-foo = ['a', 'b', 'c',]
    485 |+foo = ['a', 'b', 'c']
486 486 | 
487 487 | bar = { a: b,}
488 488 | 

COM81.py:487:13: COM819 [*] Trailing comma prohibited
    |
487 | foo = ['a', 'b', 'c',]
488 | 
489 | bar = { a: b,}
    |             ^ COM819
490 | 
491 | def bah(ham, spam,):
    |
    = help: Remove trailing comma

ℹ Suggested fix
484 484 | # ==> prohibited.py <==
485 485 | foo = ['a', 'b', 'c',]
486 486 | 
487     |-bar = { a: b,}
    487 |+bar = { a: b}
488 488 | 
489 489 | def bah(ham, spam,):
490 490 |     pass

COM81.py:489:18: COM819 [*] Trailing comma prohibited
    |
489 | bar = { a: b,}
490 | 
491 | def bah(ham, spam,):
    |                  ^ COM819
492 |     pass
    |
    = help: Remove trailing comma

ℹ Suggested fix
486 486 | 
487 487 | bar = { a: b,}
488 488 | 
489     |-def bah(ham, spam,):
    489 |+def bah(ham, spam):
490 490 |     pass
491 491 | 
492 492 | (0,)

COM81.py:494:6: COM819 [*] Trailing comma prohibited
    |
494 | (0,)
495 | 
496 | (0, 1,)
    |      ^ COM819
497 | 
498 | foo = ['a', 'b', 'c', ]
    |
    = help: Remove trailing comma

ℹ Suggested fix
491 491 | 
492 492 | (0,)
493 493 | 
494     |-(0, 1,)
    494 |+(0, 1)
495 495 | 
496 496 | foo = ['a', 'b', 'c', ]
497 497 | 

COM81.py:496:21: COM819 [*] Trailing comma prohibited
    |
496 | (0, 1,)
497 | 
498 | foo = ['a', 'b', 'c', ]
    |                     ^ COM819
499 | 
500 | bar = { a: b, }
    |
    = help: Remove trailing comma

ℹ Suggested fix
493 493 | 
494 494 | (0, 1,)
495 495 | 
496     |-foo = ['a', 'b', 'c', ]
    496 |+foo = ['a', 'b', 'c' ]
497 497 | 
498 498 | bar = { a: b, }
499 499 | 

COM81.py:498:13: COM819 [*] Trailing comma prohibited
    |
498 | foo = ['a', 'b', 'c', ]
499 | 
500 | bar = { a: b, }
    |             ^ COM819
501 | 
502 | def bah(ham, spam, ):
    |
    = help: Remove trailing comma

ℹ Suggested fix
495 495 | 
496 496 | foo = ['a', 'b', 'c', ]
497 497 | 
498     |-bar = { a: b, }
    498 |+bar = { a: b }
499 499 | 
500 500 | def bah(ham, spam, ):
501 501 |     pass

COM81.py:500:18: COM819 [*] Trailing comma prohibited
    |
500 | bar = { a: b, }
501 | 
502 | def bah(ham, spam, ):
    |                  ^ COM819
503 |     pass
    |
    = help: Remove trailing comma

ℹ Suggested fix
497 497 | 
498 498 | bar = { a: b, }
499 499 | 
500     |-def bah(ham, spam, ):
    500 |+def bah(ham, spam ):
501 501 |     pass
502 502 | 
503 503 | (0, )

COM81.py:505:6: COM819 [*] Trailing comma prohibited
    |
505 | (0, )
506 | 
507 | (0, 1, )
    |      ^ COM819
508 | 
509 | image[:, :, 0]
    |
    = help: Remove trailing comma

ℹ Suggested fix
502 502 | 
503 503 | (0, )
504 504 | 
505     |-(0, 1, )
    505 |+(0, 1 )
506 506 | 
507 507 | image[:, :, 0]
508 508 | 

COM81.py:511:10: COM819 [*] Trailing comma prohibited
    |
511 | image[:,]
512 | 
513 | image[:,:,]
    |          ^ COM819
514 | 
515 | lambda x, :
    |
    = help: Remove trailing comma

ℹ Suggested fix
508 508 | 
509 509 | image[:,]
510 510 | 
511     |-image[:,:,]
    511 |+image[:,:]
512 512 | 
513 513 | lambda x, :
514 514 | 

COM81.py:513:9: COM819 [*] Trailing comma prohibited
    |
513 | image[:,:,]
514 | 
515 | lambda x, :
    |         ^ COM819
516 | 
517 | # ==> unpack.py <==
    |
    = help: Remove trailing comma

ℹ Suggested fix
510 510 | 
511 511 | image[:,:,]
512 512 | 
513     |-lambda x, :
    513 |+lambda x :
514 514 | 
515 515 | # ==> unpack.py <==
516 516 | def function(

COM81.py:519:13: COM812 [*] Trailing comma missing
    |
519 |     foo,
520 |     bar,
521 |     **kwargs
    |              COM812
522 | ):
523 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
516 516 | def function(
517 517 |     foo,
518 518 |     bar,
519     |-    **kwargs
    519 |+    **kwargs,
520 520 | ):
521 521 |     pass
522 522 | 

COM81.py:526:10: COM812 [*] Trailing comma missing
    |
526 |     foo,
527 |     bar,
528 |     *args
    |           COM812
529 | ):
530 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
523 523 | def function(
524 524 |     foo,
525 525 |     bar,
526     |-    *args
    526 |+    *args,
527 527 | ):
528 528 |     pass
529 529 | 

COM81.py:534:16: COM812 [*] Trailing comma missing
    |
534 |     bar,
535 |     *args,
536 |     extra_kwarg
    |                 COM812
537 |     ):
538 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
531 531 |     foo,
532 532 |     bar,
533 533 |     *args,
534     |-    extra_kwarg
    534 |+    extra_kwarg,
535 535 |     ):
536 536 |     pass
537 537 | 

COM81.py:541:13: COM812 [*] Trailing comma missing
    |
541 |     foo,
542 |     bar,
543 |     **kwargs
    |              COM812
544 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
538 538 | result = function(
539 539 |     foo,
540 540 |     bar,
541     |-    **kwargs
    541 |+    **kwargs,
542 542 | )
543 543 | 
544 544 | result = function(

COM81.py:547:24: COM812 [*] Trailing comma missing
    |
547 |     foo,
548 |     bar,
549 |     **not_called_kwargs
    |                         COM812
550 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
544 544 | result = function(
545 545 |     foo,
546 546 |     bar,
547     |-    **not_called_kwargs
    547 |+    **not_called_kwargs,
548 548 | )
549 549 | 
550 550 | def foo(

COM81.py:554:15: COM812 [*] Trailing comma missing
    |
554 |     spam,
555 |     *args,
556 |     kwarg_only
    |                COM812
557 |     ):
558 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
551 551 |     ham,
552 552 |     spam,
553 553 |     *args,
554     |-    kwarg_only
    554 |+    kwarg_only,
555 555 |     ):
556 556 |     pass
557 557 | 

COM81.py:561:13: COM812 [*] Trailing comma missing
    |
561 | foo(
562 |     **kwargs
    |              COM812
563 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
558 558 | # In python 3.5 if it's not a function def, commas are mandatory.
559 559 | 
560 560 | foo(
561     |-    **kwargs
    561 |+    **kwargs,
562 562 | )
563 563 | 
564 564 | {

COM81.py:565:13: COM812 [*] Trailing comma missing
    |
565 | {
566 |     **kwargs
    |              COM812
567 | }
    |
    = help: Add trailing comma

ℹ Suggested fix
562 562 | )
563 563 | 
564 564 | {
565     |-    **kwargs
    565 |+    **kwargs,
566 566 | }
567 567 | 
568 568 | (

COM81.py:573:10: COM812 [*] Trailing comma missing
    |
573 | {
574 |     *args
    |           COM812
575 | }
    |
    = help: Add trailing comma

ℹ Suggested fix
570 570 | )
571 571 | 
572 572 | {
573     |-    *args
    573 |+    *args,
574 574 | }
575 575 | 
576 576 | [

COM81.py:577:10: COM812 [*] Trailing comma missing
    |
577 | [
578 |     *args
    |           COM812
579 | ]
    |
    = help: Add trailing comma

ℹ Suggested fix
574 574 | }
575 575 | 
576 576 | [
577     |-    *args
    577 |+    *args,
578 578 | ]
579 579 | 
580 580 | def foo(

COM81.py:583:10: COM812 [*] Trailing comma missing
    |
583 |     ham,
584 |     spam,
585 |     *args
    |           COM812
586 |     ):
587 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
580 580 | def foo(
581 581 |     ham,
582 582 |     spam,
583     |-    *args
    583 |+    *args,
584 584 |     ):
585 585 |     pass
586 586 | 

COM81.py:590:13: COM812 [*] Trailing comma missing
    |
590 |     ham,
591 |     spam,
592 |     **kwargs
    |              COM812
593 |     ):
594 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
587 587 | def foo(
588 588 |     ham,
589 589 |     spam,
590     |-    **kwargs
    590 |+    **kwargs,
591 591 |     ):
592 592 |     pass
593 593 | 

COM81.py:598:15: COM812 [*] Trailing comma missing
    |
598 |     spam,
599 |     *args,
600 |     kwarg_only
    |                COM812
601 |     ):
602 |     pass
    |
    = help: Add trailing comma

ℹ Suggested fix
595 595 |     ham,
596 596 |     spam,
597 597 |     *args,
598     |-    kwarg_only
    598 |+    kwarg_only,
599 599 |     ):
600 600 |     pass
601 601 | 

COM81.py:627:20: COM812 [*] Trailing comma missing
    |
627 |     foo,
628 |     bar,
629 |     **{'ham': spam}
    |                     COM812
630 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
624 624 | result = function(
625 625 |     foo,
626 626 |     bar,
627     |-    **{'ham': spam}
    627 |+    **{'ham': spam},
628 628 | )
629 629 | 
630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.

COM81.py:632:42: COM812 [*] Trailing comma missing
    |
632 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.
633 | the_first_one = next(
634 |     (i for i in range(10) if i // 2 == 0)  # COM812 fix should include the final bracket
    |                                           COM812
635 | )
    |
    = help: Add trailing comma

ℹ Suggested fix
629 629 | 
630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.
631 631 | the_first_one = next(
632     |-    (i for i in range(10) if i // 2 == 0)  # COM812 fix should include the final bracket
    632 |+    (i for i in range(10) if i // 2 == 0),  # COM812 fix should include the final bracket
633 633 | )


