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

COM812 [*] Trailing comma missing
  --> COM81.py:10:6
   |
 8 |     1,
 9 |     2,
10 |     3
   |      ^
11 | ]
   |
help: Add trailing comma
   |
9  |     2,
   -     3
10 +     3,
11 | ]
   |

COM812 [*] Trailing comma missing
  --> COM81.py:16:6
   |
14 |     1,
15 |     2,
16 |     3
   |      ^
17 |     # still needs a comma!
18 | ]
   |
help: Add trailing comma
   |
15 |     2,
   -     3
16 +     3,
17 |     # still needs a comma!
   |

COM812 [*] Trailing comma missing
  --> COM81.py:23:6
   |
21 |     1,
22 |     2,
23 |     3
   |      ^
   |
help: Add trailing comma
   |
22 |     2,
   -     3
23 +     3,
24 |
   |

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

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

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

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

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

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

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

COM812 [*] Trailing comma missing
  --> COM81.py:70:8
   |
69 | {'foo': foo}['foo'](
70 |     bar
   |        ^
71 | )
   |
help: Add trailing comma
   |
69 | {'foo': foo}['foo'](
   -     bar
70 +     bar,
71 | )
   |

COM812 [*] Trailing comma missing
  --> COM81.py:78:8
   |
77 | (foo)(
78 |     bar
   |        ^
79 | )
   |
help: Add trailing comma
   |
77 | (foo)(
   -     bar
78 +     bar,
79 | )
   |

COM812 [*] Trailing comma missing
  --> COM81.py:86:8
   |
85 | [foo][0](
86 |     bar
   |        ^
87 | )
   |
help: Add trailing comma
   |
85 | [foo][0](
   -     bar
86 +     bar,
87 | )
   |

COM812 [*] Trailing comma missing
   --> COM81.py:152:6
    |
150 | # ==> keyword_before_parenth_form/base_bad.py <==
151 | from x import (
152 |     y
    |      ^
153 | )
    |
help: Add trailing comma
    |
151 | from x import (
    -     y
152 +     y,
153 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:158:11
    |
156 |     SyntaxWarning,
157 |     ThrownHere,
158 |     Anyway
    |           ^
159 | )
    |
help: Add trailing comma
    |
157 |     ThrownHere,
    -     Anyway
158 +     Anyway,
159 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:293:15
    |
291 | # ==> multiline_bad_dict.py <==
292 | multiline_bad_dict = {
293 |     "bad": 123
    |               ^
294 | }
295 | # ==> multiline_bad_function_def.py <==
    |
help: Add trailing comma
    |
292 | multiline_bad_dict = {
    -     "bad": 123
293 +     "bad": 123,
294 | }
    |

COM812 [*] Trailing comma missing
   --> COM81.py:304:14
    |
302 | def func_bad(
303 |         a = 3,
304 |         b = 2
    |              ^
305 |     ):
306 |     pass
    |
help: Add trailing comma
    |
303 |         a = 3,
    -         b = 2
304 +         b = 2,
305 |     ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:310:14
    |
308 | # ==> multiline_bad_function_one_param.py <==
309 | def func(
310 |         a = 3
    |              ^
311 |     ):
312 |     pass
    |
help: Add trailing comma
    |
309 | def func(
    -         a = 3
310 +         a = 3,
311 |     ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:316:10
    |
315 | func(
316 |     a = 3
    |          ^
317 | )
    |
help: Add trailing comma
    |
315 | func(
    -     a = 3
316 +     a = 3,
317 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:322:15
    |
320 | multiline_bad_or_dict = {
321 |     "good": True or False,
322 |     "bad": 123
    |               ^
323 | }
    |
help: Add trailing comma
    |
321 |     "good": True or False,
    -     "bad": 123
322 +     "bad": 123,
323 | }
    |

COM812 [*] Trailing comma missing
   --> COM81.py:368:15
    |
366 | multiline_index_access[
367 |     "probably fine",
368 |     "not good"
    |               ^
369 | ]
    |
help: Add trailing comma
    |
367 |     "probably fine",
    -     "not good"
368 +     "not good",
369 | ]
    |

COM812 [*] Trailing comma missing
   --> COM81.py:375:15
    |
373 |     "fine",
374 |     :
375 |     "not good"
    |               ^
376 | ]
    |
help: Add trailing comma
    |
374 |     :
    -     "not good"
375 +     "not good",
376 | ]
    |

COM812 [*] Trailing comma missing
   --> COM81.py:404:15
    |
402 |     "fine"
403 |     :
404 |     "not fine"
    |               ^
405 | ]
    |
help: Add trailing comma
    |
403 |     :
    -     "not fine"
404 +     "not fine",
405 | ]
    |

COM812 [*] Trailing comma missing
   --> COM81.py:432:15
    |
430 |     :
431 |     "fine",
432 |     "not fine"
    |               ^
433 | ]
    |
help: Add trailing comma
    |
431 |     "fine",
    -     "not fine"
432 +     "not fine",
433 | ]
    |

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

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

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

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

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

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

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

COM819 [*] Trailing comma prohibited
   --> COM81.py:505:6
    |
503 | (0, )
504 |
505 | (0, 1, )
    |      ^
506 |
507 | image[:, :, 0]
    |
help: Remove trailing comma
    |
504 |
    - (0, 1, )
505 + (0, 1 )
506 |
    |

COM819 [*] Trailing comma prohibited
   --> COM81.py:511:10
    |
509 | image[:,]
510 |
511 | image[:,:,]
    |          ^
512 |
513 | lambda x, : x
    |
help: Remove trailing comma
    |
510 |
    - image[:,:,]
511 + image[:,:]
512 |
    |

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

COM812 [*] Trailing comma missing
   --> COM81.py:519:13
    |
517 |     foo,
518 |     bar,
519 |     **kwargs
    |             ^
520 | ):
521 |     pass
    |
help: Add trailing comma
    |
518 |     bar,
    -     **kwargs
519 +     **kwargs,
520 | ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:526:10
    |
524 |     foo,
525 |     bar,
526 |     *args
    |          ^
527 | ):
528 |     pass
    |
help: Add trailing comma
    |
525 |     bar,
    -     *args
526 +     *args,
527 | ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:534:16
    |
532 |     bar,
533 |     *args,
534 |     extra_kwarg
    |                ^
535 |     ):
536 |     pass
    |
help: Add trailing comma
    |
533 |     *args,
    -     extra_kwarg
534 +     extra_kwarg,
535 |     ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:541:13
    |
539 |     foo,
540 |     bar,
541 |     **kwargs
    |             ^
542 | )
    |
help: Add trailing comma
    |
540 |     bar,
    -     **kwargs
541 +     **kwargs,
542 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:547:24
    |
545 |     foo,
546 |     bar,
547 |     **not_called_kwargs
    |                        ^
548 | )
    |
help: Add trailing comma
    |
546 |     bar,
    -     **not_called_kwargs
547 +     **not_called_kwargs,
548 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:554:15
    |
552 |     spam,
553 |     *args,
554 |     kwarg_only
    |               ^
555 |     ):
556 |     pass
    |
help: Add trailing comma
    |
553 |     *args,
    -     kwarg_only
554 +     kwarg_only,
555 |     ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:561:13
    |
560 | foo(
561 |     **kwargs
    |             ^
562 | )
    |
help: Add trailing comma
    |
560 | foo(
    -     **kwargs
561 +     **kwargs,
562 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:565:13
    |
564 | {
565 |     **kwargs
    |             ^
566 | }
    |
help: Add trailing comma
    |
564 | {
    -     **kwargs
565 +     **kwargs,
566 | }
    |

COM812 [*] Trailing comma missing
   --> COM81.py:569:10
    |
568 | {
569 |     *args
    |          ^
570 | }
    |
help: Add trailing comma
    |
568 | {
    -     *args
569 +     *args,
570 | }
    |

COM812 [*] Trailing comma missing
   --> COM81.py:573:10
    |
572 | [
573 |     *args
    |          ^
574 | ]
    |
help: Add trailing comma
    |
572 | [
    -     *args
573 +     *args,
574 | ]
    |

COM812 [*] Trailing comma missing
   --> COM81.py:579:10
    |
577 |     ham,
578 |     spam,
579 |     *args
    |          ^
580 |     ):
581 |     pass
    |
help: Add trailing comma
    |
578 |     spam,
    -     *args
579 +     *args,
580 |     ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:586:13
    |
584 |     ham,
585 |     spam,
586 |     **kwargs
    |             ^
587 |     ):
588 |     pass
    |
help: Add trailing comma
    |
585 |     spam,
    -     **kwargs
586 +     **kwargs,
587 |     ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:594:15
    |
592 |     spam,
593 |     *args,
594 |     kwarg_only
    |               ^
595 |     ):
596 |     pass
    |
help: Add trailing comma
    |
593 |     *args,
    -     kwarg_only
594 +     kwarg_only,
595 |     ):
    |

COM812 [*] Trailing comma missing
   --> COM81.py:623:20
    |
621 |     foo,
622 |     bar,
623 |     **{'ham': spam}
    |                    ^
624 | )
    |
help: Add trailing comma
    |
622 |     bar,
    -     **{'ham': spam}
623 +     **{'ham': spam},
624 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:628:42
    |
626 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error.
627 | the_first_one = next(
628 |     (i for i in range(10) if i // 2 == 0)  # COM812 fix should include the final bracket
    |                                          ^
629 | )
    |
help: Add trailing comma
    |
627 | the_first_one = next(
    -     (i for i in range(10) if i // 2 == 0)  # COM812 fix should include the final bracket
628 +     (i for i in range(10) if i // 2 == 0),  # COM812 fix should include the final bracket
629 | )
    |

COM819 [*] Trailing comma prohibited
   --> COM81.py:640:46
    |
639 | # F-strings
640 | kwargs.pop("remove", f"this {trailing_comma}",)
    |                                              ^
641 |
642 | raise Exception(
    |
help: Remove trailing comma
    |
639 | # F-strings
    - kwargs.pop("remove", f"this {trailing_comma}",)
640 + kwargs.pop("remove", f"this {trailing_comma}")
641 |
    |

COM812 [*] Trailing comma missing
   --> COM81.py:643:49
    |
642 | raise Exception(
643 |     "first", extra=f"Add trailing comma here ->"
    |                                                 ^
644 | )
    |
help: Add trailing comma
    |
642 | raise Exception(
    -     "first", extra=f"Add trailing comma here ->"
643 +     "first", extra=f"Add trailing comma here ->",
644 | )
    |

COM812 [*] Trailing comma missing
   --> COM81.py:655:6
    |
654 | type X[
655 |     T
    |      ^
656 | ] = T
657 | def f[
    |
help: Add trailing comma
    |
654 | type X[
    -     T
655 +     T,
656 | ] = T
    |

COM812 [*] Trailing comma missing
   --> COM81.py:658:6
    |
656 | ] = T
657 | def f[
658 |     T
    |      ^
659 | ](): pass
660 | class C[
    |
help: Add trailing comma
    |
657 | def f[
    -     T
658 +     T,
659 | ](): pass
    |

COM812 [*] Trailing comma missing
   --> COM81.py:661:6
    |
659 | ](): pass
660 | class C[
661 |     T
    |      ^
662 | ]: pass
    |
help: Add trailing comma
    |
660 | class C[
    -     T
661 +     T,
662 | ]: pass
    |

COM819 [*] Trailing comma prohibited
   --> COM81.py:664:9
    |
662 | ]: pass
663 |
664 | type X[T,] = T
    |         ^
665 | def f[T,](): pass
666 | class C[T,]: pass
    |
help: Remove trailing comma
    |
663 |
    - type X[T,] = T
664 + type X[T] = T
665 | def f[T,](): pass
    |

COM819 [*] Trailing comma prohibited
   --> COM81.py:665:8
    |
664 | type X[T,] = T
665 | def f[T,](): pass
    |        ^
666 | class C[T,]: pass
    |
help: Remove trailing comma
    |
664 | type X[T,] = T
    - def f[T,](): pass
665 + def f[T](): pass
666 | class C[T,]: pass
    |

COM819 [*] Trailing comma prohibited
   --> COM81.py:666:10
    |
664 | type X[T,] = T
665 | def f[T,](): pass
666 | class C[T,]: pass
    |          ^
667 |
668 | # t-string examples
    |
help: Remove trailing comma
    |
665 | def f[T,](): pass
    - class C[T,]: pass
666 + class C[T]: pass
667 |
    |

COM819 [*] Trailing comma prohibited
   --> COM81.py:669:46
    |
668 | # t-string examples
669 | kwargs.pop("remove", t"this {trailing_comma}",)
    |                                              ^
670 | kwargs.pop("remove", t"this {f"{trailing_comma}"}",)
    |
help: Remove trailing comma
    |
668 | # t-string examples
    - kwargs.pop("remove", t"this {trailing_comma}",)
669 + kwargs.pop("remove", t"this {trailing_comma}")
670 | kwargs.pop("remove", t"this {f"{trailing_comma}"}",)
    |

COM819 [*] Trailing comma prohibited
   --> COM81.py:670:51
    |
668 | # t-string examples
669 | kwargs.pop("remove", t"this {trailing_comma}",)
670 | kwargs.pop("remove", t"this {f"{trailing_comma}"}",)
    |                                                   ^
671 |
672 | t"""This is a test. {
    |
help: Remove trailing comma
    |
669 | kwargs.pop("remove", t"this {trailing_comma}",)
    - kwargs.pop("remove", t"this {f"{trailing_comma}"}",)
670 + kwargs.pop("remove", t"this {f"{trailing_comma}"}")
671 |
    |
