astral-sh/ruff

PT007 shows wrong type in violation message

クローズ

#14,743 opened on 2024/12/02

 (6 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (2,088 件のフォーク)batch import
help wantedrule

Repository metrics

Stars
 (47,527 個のスター)
PR merge metrics
 (平均マージ 3d 8h) (30d で 573 merged PRs)

説明

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.

コントリビューターガイド