From fe18e5d2f65f4267c380738041fde6341e16a2df Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 24 May 2024 10:04:49 +0200 Subject: [PATCH] type ignore comments compatibility between pyright and mypy --- .github/workflows/test.yml | 3 +-- pyrightconfig.testcases.json | 4 ++-- tests/assert_type/db/models/check_enums.py | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c11636f6..4ea7d82e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,8 +70,7 @@ jobs: - name: Run pytest tests run: PYTHONPATH='.' pytest --num-shards=4 --shard-id=${{ matrix.shard }} tests - name: Run mypy on the test cases - # TODO: When mypy aligns with pyright, remove the `--no-warn-unused-ignores`. - run: mypy tests/assert_type --no-warn-unused-ignores + run: mypy tests/assert_type stubtest: timeout-minutes: 10 diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json index c38933315..f939a0905 100644 --- a/pyrightconfig.testcases.json +++ b/pyrightconfig.testcases.json @@ -9,8 +9,8 @@ "reportImplicitStringConcatenation": "error", "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", - // Using unspecific `type: ignore` comments in test_cases. - "enableTypeIgnoreComments": true, + // Don't use '# type: ignore' to suppress with pyright + "enableTypeIgnoreComments": false, // If a test case uses this anti-pattern, there's likely a reason and annoying to `type: ignore`. // Let Ruff flag it (B006) "reportCallInDefaultInitializer": "none", diff --git a/tests/assert_type/db/models/check_enums.py b/tests/assert_type/db/models/check_enums.py index 5282e5449..2c88d76f5 100644 --- a/tests/assert_type/db/models/check_enums.py +++ b/tests/assert_type/db/models/check_enums.py @@ -8,9 +8,9 @@ class MyIntegerChoices(IntegerChoices): A = 1 B = 2, "B" - C = 3, "B", "..." # type: ignore + C = 3, "B", "..." # pyright: ignore[reportCallIssue] D = 4, _("D") - E = 5, 1 # type: ignore + E = 5, 1 # pyright: ignore[reportArgumentType] F = "1" @@ -29,8 +29,8 @@ class MyTextChoices(TextChoices): A = "a" B = "b", "B" C = "c", _("C") - D = 1 # type: ignore - E = "e", 1 # type: ignore + D = 1 # pyright: ignore[reportArgumentType] + E = "e", 1 # pyright: ignore[reportArgumentType] assert_type(MyTextChoices.A, Literal[MyTextChoices.A])