From e68c3742bf5e949e91511c2ecf3eabcda4077f28 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 5 Sep 2022 00:51:08 +0100 Subject: [PATCH 1/3] Enable pyright's `reportUnnecessaryTypeIgnoreComment` setting for the whole `test_cases` directory --- .github/workflows/tests.yml | 7 ++++ pyrightconfig.json | 3 +- pyrightconfig.stricter.json | 3 +- pyrightconfig.testcases.json | 51 +++++++++++++++++++++++++ test_cases/README.md | 7 +--- test_cases/stdlib/builtins/test_dict.py | 2 - test_cases/stdlib/builtins/test_pow.py | 2 - test_cases/stdlib/builtins/test_sum.py | 2 - test_cases/stdlib/test_codecs.py | 2 - test_cases/stdlib/test_unittest.py | 2 - 10 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 pyrightconfig.testcases.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f56ace97f485..9b5783e015db 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -105,6 +105,13 @@ jobs: python-platform: ${{ matrix.python-platform }} python-version: ${{ matrix.python-version }} no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. + project: ./pyrightconfig.testcases.json + - uses: jakebailey/pyright-action@v1 + with: + version: ${{ env.PYRIGHT_VERSION }} + python-platform: ${{ matrix.python-platform }} + python-version: ${{ matrix.python-version }} + no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. stubtest-third-party: name: Check third party stubs with stubtest diff --git a/pyrightconfig.json b/pyrightconfig.json index 923f815ebae3..0851d5654db6 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -2,8 +2,7 @@ "typeshedPath": ".", "include": [ "stdlib", - "stubs", - "test_cases" + "stubs" ], "typeCheckingMode": "basic", "strictListInference": true, diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index f257208ecd13..c8ad0c8bb35b 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -3,8 +3,7 @@ "typeshedPath": ".", "include": [ "stdlib", - "stubs", - "test_cases" + "stubs" ], "exclude": [ "stdlib/distutils/command", diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json new file mode 100644 index 000000000000..0e0ec73f0395 --- /dev/null +++ b/pyrightconfig.testcases.json @@ -0,0 +1,51 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json", + "typeshedPath": ".", + "include": [ + "test_cases" + ], + "typeCheckingMode": "basic", + "strictListInference": true, + "strictDictionaryInference": true, + "strictParameterNoneValue": true, + "reportFunctionMemberAccess": "error", + "reportMissingModuleSource": "none", + "reportMissingTypeStubs": "error", + "reportUnusedImport": "error", + "reportUnusedClass": "error", + "reportUnusedFunction": "error", + "reportUnusedVariable": "error", + "reportDuplicateImport": "error", + "reportOptionalSubscript": "error", + "reportOptionalMemberAccess": "error", + "reportOptionalCall": "error", + "reportOptionalIterable": "error", + "reportOptionalContextManager": "error", + "reportOptionalOperand": "error", + "reportUntypedFunctionDecorator": "error", + "reportUntypedClassDecorator": "error", + "reportUntypedBaseClass": "error", + "reportUntypedNamedTuple": "error", + "reportPrivateUsage": "none", + "reportConstantRedefinition": "error", + "reportInvalidStringEscapeSequence": "error", + "reportUnknownParameterType": "error", + "reportUnknownArgumentType": "error", + "reportUnknownLambdaType": "error", + "reportUnknownVariableType": "error", + "reportUnknownMemberType": "error", + "reportMissingTypeArgument": "error", + "reportUndefinedVariable": "error", + "reportUnboundVariable": "error", + "reportInvalidStubStatement": "error", + "reportInvalidTypeVarUse": "error", + "reportPropertyTypeMismatch": "error", + "reportSelfClsParameterName": "error", + "reportUnsupportedDunderAll": "error", + "reportIncompatibleMethodOverride": "error", + "reportIncompatibleVariableOverride": "error", + "reportOverlappingOverload": "error", + "reportUnnecessaryTypeIgnoreComment": "error", + "reportMissingTypeStubs": "error", + "reportMatchNotExhaustive": "error" +} diff --git a/test_cases/README.md b/test_cases/README.md index d15382e15a27..d343f9ac0cad 100644 --- a/test_cases/README.md +++ b/test_cases/README.md @@ -40,11 +40,8 @@ mypy's setting and pyright's [`reportUnnecessaryTypeIgnoreComment`](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#type-check-diagnostics-settings) setting) to test instances where a type checker *should* emit some kind of -error, if the stubs are correct. Note that mypy's `--warn-unused-ignores` -setting is enabled for the entire subdirectory; however, the pyright setting -must be enabled on a per-file basis with -`# pyright: reportUnnecessaryTypeIgnoreComment=true` at the the top of the -file. +error, if the stubs are correct. Both settings are enabled by default for the entire +subdirectory. For more information on using `assert_type` and `--warn-unused-ignores`/`reportUnnecessaryTypeIgnoreComment` to test type diff --git a/test_cases/stdlib/builtins/test_dict.py b/test_cases/stdlib/builtins/test_dict.py index 08f763333fec..b2def8b9a017 100644 --- a/test_cases/stdlib/builtins/test_dict.py +++ b/test_cases/stdlib/builtins/test_dict.py @@ -1,5 +1,3 @@ -# pyright: reportUnnecessaryTypeIgnoreComment=true - from typing import Dict, Generic, Iterable, Tuple, TypeVar from typing_extensions import assert_type diff --git a/test_cases/stdlib/builtins/test_pow.py b/test_cases/stdlib/builtins/test_pow.py index 732dfca58d54..c1ff7497e165 100644 --- a/test_cases/stdlib/builtins/test_pow.py +++ b/test_cases/stdlib/builtins/test_pow.py @@ -1,5 +1,3 @@ -# pyright: reportUnnecessaryTypeIgnoreComment=true - from decimal import Decimal from fractions import Fraction from typing import Any diff --git a/test_cases/stdlib/builtins/test_sum.py b/test_cases/stdlib/builtins/test_sum.py index 421116767f56..0f256fd2fc7d 100644 --- a/test_cases/stdlib/builtins/test_sum.py +++ b/test_cases/stdlib/builtins/test_sum.py @@ -1,5 +1,3 @@ -# pyright: reportUnnecessaryTypeIgnoreComment=true - from typing import Any, List, Union from typing_extensions import Literal, assert_type diff --git a/test_cases/stdlib/test_codecs.py b/test_cases/stdlib/test_codecs.py index dfbc46db72b9..0657416bcb3c 100644 --- a/test_cases/stdlib/test_codecs.py +++ b/test_cases/stdlib/test_codecs.py @@ -1,5 +1,3 @@ -# pyright: reportUnnecessaryTypeIgnoreComment=true - import codecs from typing_extensions import assert_type diff --git a/test_cases/stdlib/test_unittest.py b/test_cases/stdlib/test_unittest.py index 5d1efc1b0bc9..b8a16e7ef785 100644 --- a/test_cases/stdlib/test_unittest.py +++ b/test_cases/stdlib/test_unittest.py @@ -1,5 +1,3 @@ -# pyright: reportUnnecessaryTypeIgnoreComment=true - import unittest from datetime import datetime, timedelta from decimal import Decimal From e46b4c063f9fe4a3a7ffc66ef2ed84d89660d1ab Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 5 Sep 2022 00:51:52 +0100 Subject: [PATCH 2/3] Add an unnecessary `type: ignore`, to show it works --- test_cases/stdlib/builtins/test_pow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cases/stdlib/builtins/test_pow.py b/test_cases/stdlib/builtins/test_pow.py index c1ff7497e165..ea0cc33cf34e 100644 --- a/test_cases/stdlib/builtins/test_pow.py +++ b/test_cases/stdlib/builtins/test_pow.py @@ -14,7 +14,7 @@ # # assert_type(pow(2, 4, 0), NoReturn) -assert_type(pow(2, 4), int) +assert_type(pow(2, 4), int) # type: ignore assert_type(2**4, int) assert_type(pow(4, 6, None), int) From 455934445bda41deb0fe962389bb0d7c34e033a9 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 5 Sep 2022 00:56:44 +0100 Subject: [PATCH 3/3] Revert the addition of the unnecessary `type: ignore` comment --- test_cases/stdlib/builtins/test_pow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cases/stdlib/builtins/test_pow.py b/test_cases/stdlib/builtins/test_pow.py index ea0cc33cf34e..c1ff7497e165 100644 --- a/test_cases/stdlib/builtins/test_pow.py +++ b/test_cases/stdlib/builtins/test_pow.py @@ -14,7 +14,7 @@ # # assert_type(pow(2, 4, 0), NoReturn) -assert_type(pow(2, 4), int) # type: ignore +assert_type(pow(2, 4), int) assert_type(2**4, int) assert_type(pow(4, 6, None), int)