astral-sh/ruff

PT007 shows wrong type in violation message

Open

Aperta il 2 dic 2024

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)Rust (47.527 star) (2088 fork)batch import
help wantedrule

Descrizione

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.

Guida contributor