astral-sh/ruff

PT007 shows wrong type in violation message

Open

#14,743 建立於 2024年12月2日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)Rust (47,527 star) (2,088 fork)batch import
help wantedrule

描述

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.

貢獻者指南