astral-sh/ruff

PT007 shows wrong type in violation message

Geschlossen

#14.743 geöffnet am 02.12.2024

 (6 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (2.088 Forks)batch import
help wantedrule

Repository-Metriken

Stars
 (47.527 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 3T 8h) (573 gemergte PRs in 30 T)

Beschreibung

The violation message shows the same type twice, even though one of them should be list.

import pytest


@pytest.mark.parametrize('foo', [{'bar': 1}, {'baz': 1}])
def test_test(foo):
    pass
$ ruff version
ruff 0.8.1
$ ruff check --isolated --select PT007 --config "lint.flake8-pytest-style.parametrize-values-type = 'tuple'" --preview --no-cache rufftest/ruff_sample.py
rufftest/ruff_sample.py:4:33: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
  |
4 | @pytest.mark.parametrize('foo', [{'bar': 1}, {'baz': 1}])
  |                                 ^^^^^^^^^^^^^^^^^^^^^^^^ PT007
5 | def test_test(foo):
6 |     pass
  |
  = help: Use `tuple` of `tuple` for parameter values

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

The fix looks fine though so this is just a wrong message:

$ ruff check --isolated --select PT007 --config "lint.flake8-pytest-style.parametrize-values-type = 'tuple'" --preview --no-cache rufftest/ruff_sample.py --diff --unsafe-fixes
--- rufftest/ruff_sample.py
+++ rufftest/ruff_sample.py
@@ -1,6 +1,6 @@
 import pytest


-@pytest.mark.parametrize('foo', [{'bar': 1}, {'baz': 1}])
+@pytest.mark.parametrize('foo', ({'bar': 1}, {'baz': 1}))
 def test_test(foo):
     pass

Would fix 1 error.

Contributor Guide