Skip to content

Confusing error message for C401 and C416 #10101

@runfalk

Description

@runfalk

I ran into this oddity. The suggested fix for C401 actually results in C416 because i isn't transformed in any way. Is there a better way to indicate this in the error message?

_a = set(i for i in range(10))
_b = {i for i in range(10)}
_c = set(range(10))
$ poetry run ruff check --output-format full test.py
test.py:1:6: C401 Unnecessary generator (rewrite as a `set` comprehension)
  |
1 | _a = set(i for i in range(10))
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^ C401
2 | _b = {i for i in range(10)}
3 | _c = set(range(10))
  |
  = help: Rewrite as a `set` comprehension

test.py:2:6: C416 Unnecessary `set` comprehension (rewrite using `set()`)
  |
1 | _a = set(i for i in range(10))
2 | _b = {i for i in range(10)}
  |      ^^^^^^^^^^^^^^^^^^^^^^ C416
3 | _c = set(range(10))
  |
  = help: Rewrite using `set()`

Found 2 errors.
No fixes available (2 hidden fixes can be enabled with the `--unsafe-fixes` option).
$ poetry run ruff --version
ruff 0.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions