From a06a29316d67e57d48211e1e46889fca6ac98d38 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 11 Feb 2023 13:53:27 -0500 Subject: [PATCH 1/6] Simplify configs and add missing comments --- pyrightconfig.json | 34 ++++++++-------------------------- pyrightconfig.stricter.json | 5 +++-- pyrightconfig.testcases.json | 7 +++++-- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index 9fc8f5f5faa4..bcc8520e9608 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -9,32 +9,14 @@ // test cases use a custom config file "stubs/**/@tests/test_cases" ], - "typeCheckingMode": "basic", - "strictListInference": true, - "strictDictionaryInference": true, - "strictSetInference": true, - "reportFunctionMemberAccess": "error", - "reportMissingTypeStubs": "error", - "reportUnusedImport": "error", - "reportUnusedClass": "error", - "reportUnusedFunction": "error", - "reportUnusedVariable": "error", - "reportDuplicateImport": "error", - "reportUntypedFunctionDecorator": "error", - "reportUntypedClassDecorator": "error", - "reportUntypedBaseClass": "error", - "reportUntypedNamedTuple": "error", - "reportConstantRedefinition": "error", - "reportInvalidStringEscapeSequence": "error", - "reportUnknownArgumentType": "error", - "reportUnknownLambdaType": "error", - "reportMissingTypeArgument": "error", - "reportInvalidStubStatement": "error", - "reportInvalidTypeVarUse": "error", - "reportUnsupportedDunderAll": "error", - "reportInconsistentConstructor": "error", - "reportTypeCommentUsage": "error", - "reportUnnecessaryComparison": "error", + "typeCheckingMode": "strict", + // Allowed in base settings for incomplete stubs, checked in stricter settings + "reportIncompleteStub": "none", + "reportMissingParameterType": "none", + "reportUnknownMemberType": "none", + "reportUnknownParameterType": "none", + "reportUnknownVariableType": "none", + // Extra strict settings "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index dc8605bfe8c6..37fde5cca1e7 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -75,13 +75,14 @@ "stubs/vobject", ], "typeCheckingMode": "strict", + // TODO: Complete incomplete stubs + "reportIncompleteStub": "none", + // Extra strict settings "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, // Stubs are allowed to use private variables "reportPrivateUsage": "none", - // TODO: Complete incomplete stubs - "reportIncompleteStub": "none", // Stubs don't need the actual modules to be installed "reportMissingModuleSource": "none", // Incompatible overrides and property type mismatches are out of typeshed's control diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json index 13a7d8b37579..99a8900224a8 100644 --- a/pyrightconfig.testcases.json +++ b/pyrightconfig.testcases.json @@ -6,12 +6,15 @@ "stubs/**/@tests/test_cases" ], "typeCheckingMode": "strict", + // Extra strict settings + "reportPropertyTypeMismatch": "error", + "reportUnnecessaryTypeIgnoreComment": "error", // Using unspecific "type ignore" comments in test_cases. // See https://github.com/python/typeshed/pull/8083 "enableTypeIgnoreComments": true, - "reportPropertyTypeMismatch": "error", - "reportUnnecessaryTypeIgnoreComment": "error", + // Stubs don't need the actual modules to be installed "reportMissingModuleSource": "none", + // Stubs are allowed to use private variables. We may want to test those. "reportPrivateUsage": "none", // isinstance checks are still needed when validating inputs outside of typeshed's control "reportUnnecessaryIsInstance": "none", From f2b0c3cfd4ea5204bee8f73915e163dc71e3924b Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 11 Feb 2023 14:20:57 -0500 Subject: [PATCH 2/6] Apply settings not on by default with strict mode --- pyrightconfig.json | 6 ++++++ pyrightconfig.stricter.json | 6 ++++++ pyrightconfig.testcases.json | 5 +++++ test_cases/stdlib/asyncio/check_task.py | 2 +- test_cases/stdlib/builtins/check_dict.py | 2 +- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index bcc8520e9608..e42b3e9019bf 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -17,9 +17,15 @@ "reportUnknownParameterType": "none", "reportUnknownVariableType": "none", // Extra strict settings + "reportCallInDefaultInitializer": "error", + "reportImplicitStringConcatenation": "error", + "reportMissingSuperCall": "error", + "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, + // stdlib stubs trigger reportShadowedImports + "reportShadowedImports": "none", // Stubs are allowed to use private variables "reportPrivateUsage": "none", // Stubs don't need the actual modules to be installed diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 37fde5cca1e7..a7c1e02addcd 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -78,9 +78,15 @@ // TODO: Complete incomplete stubs "reportIncompleteStub": "none", // Extra strict settings + "reportCallInDefaultInitializer": "error", + "reportImplicitStringConcatenation": "error", + "reportMissingSuperCall": "error", + "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, + // stdlib stubs trigger reportShadowedImports + "reportShadowedImports": "none", // Stubs are allowed to use private variables "reportPrivateUsage": "none", // Stubs don't need the actual modules to be installed diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json index 99a8900224a8..33ae6eeab8ab 100644 --- a/pyrightconfig.testcases.json +++ b/pyrightconfig.testcases.json @@ -7,7 +7,12 @@ ], "typeCheckingMode": "strict", // Extra strict settings + "reportShadowedImports": "error", + "reportCallInDefaultInitializer": "error", + "reportImplicitStringConcatenation": "error", + "reportMissingSuperCall": "error", "reportPropertyTypeMismatch": "error", + "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Using unspecific "type ignore" comments in test_cases. // See https://github.com/python/typeshed/pull/8083 diff --git a/test_cases/stdlib/asyncio/check_task.py b/test_cases/stdlib/asyncio/check_task.py index 69bcf8f782aa..b475d509ff5d 100644 --- a/test_cases/stdlib/asyncio/check_task.py +++ b/test_cases/stdlib/asyncio/check_task.py @@ -4,7 +4,7 @@ class Waiter: - def __init__(self) -> None: + def __init__(self) -> None: # pyright: ignore [reportMissingSuperCall] # Is this a false-positive? self.tasks: list[asyncio.Task[object]] = [] def add(self, t: asyncio.Task[object]) -> None: diff --git a/test_cases/stdlib/builtins/check_dict.py b/test_cases/stdlib/builtins/check_dict.py index 2161bb2647eb..9f2dc8c88fa6 100644 --- a/test_cases/stdlib/builtins/check_dict.py +++ b/test_cases/stdlib/builtins/check_dict.py @@ -18,7 +18,7 @@ class KeysAndGetItem(Generic[_KT, _VT]): - data: dict[_KT, _VT] + data: dict[_KT, _VT] = {} def keys(self) -> Iterable[_KT]: return self.data.keys() From fa54443c0aab04055b5e0d7f81024aa062c216b2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 12 Feb 2023 00:26:38 -0500 Subject: [PATCH 3/6] Update `reportMissingSuperCall` with comment --- pyrightconfig.json | 3 ++- pyrightconfig.stricter.json | 3 ++- pyrightconfig.testcases.json | 5 +++-- test_cases/stdlib/asyncio/check_task.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index e42b3e9019bf..704a672b92a9 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -19,11 +19,12 @@ // Extra strict settings "reportCallInDefaultInitializer": "error", "reportImplicitStringConcatenation": "error", - "reportMissingSuperCall": "error", "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, + // Too strict and has no effect in stubs + "reportMissingSuperCall": "none", // stdlib stubs trigger reportShadowedImports "reportShadowedImports": "none", // Stubs are allowed to use private variables diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index a7c1e02addcd..a46fd63f4eef 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -80,11 +80,12 @@ // Extra strict settings "reportCallInDefaultInitializer": "error", "reportImplicitStringConcatenation": "error", - "reportMissingSuperCall": "error", "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, + // Too strict and has no effect in stubs + "reportMissingSuperCall": "none", // stdlib stubs trigger reportShadowedImports "reportShadowedImports": "none", // Stubs are allowed to use private variables diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json index 33ae6eeab8ab..38c1600a62ed 100644 --- a/pyrightconfig.testcases.json +++ b/pyrightconfig.testcases.json @@ -7,16 +7,17 @@ ], "typeCheckingMode": "strict", // Extra strict settings - "reportShadowedImports": "error", + "reportShadowedImports": "error", // Don't accidentally name a file something that shadows stdlib "reportCallInDefaultInitializer": "error", "reportImplicitStringConcatenation": "error", - "reportMissingSuperCall": "error", "reportPropertyTypeMismatch": "error", "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Using unspecific "type ignore" comments in test_cases. // See https://github.com/python/typeshed/pull/8083 "enableTypeIgnoreComments": true, + // Too strict and not needed for type testing + "reportMissingSuperCall": "none", // Stubs don't need the actual modules to be installed "reportMissingModuleSource": "none", // Stubs are allowed to use private variables. We may want to test those. diff --git a/test_cases/stdlib/asyncio/check_task.py b/test_cases/stdlib/asyncio/check_task.py index b475d509ff5d..69bcf8f782aa 100644 --- a/test_cases/stdlib/asyncio/check_task.py +++ b/test_cases/stdlib/asyncio/check_task.py @@ -4,7 +4,7 @@ class Waiter: - def __init__(self) -> None: # pyright: ignore [reportMissingSuperCall] # Is this a false-positive? + def __init__(self) -> None: self.tasks: list[asyncio.Task[object]] = [] def add(self, t: asyncio.Task[object]) -> None: From b321523821bec28d5a1abd6102e9a3de6d74d87d Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 12 Feb 2023 08:47:04 -0500 Subject: [PATCH 4/6] Pr comment Incidentally also test generic params inferred from __init__ call --- test_cases/stdlib/builtins/check_dict.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test_cases/stdlib/builtins/check_dict.py b/test_cases/stdlib/builtins/check_dict.py index 9f2dc8c88fa6..66c9e9a1add0 100644 --- a/test_cases/stdlib/builtins/check_dict.py +++ b/test_cases/stdlib/builtins/check_dict.py @@ -18,7 +18,10 @@ class KeysAndGetItem(Generic[_KT, _VT]): - data: dict[_KT, _VT] = {} + data: dict[_KT, _VT] + + def __init__(self, data: dict[_KT, _VT]): + self.data = data def keys(self) -> Iterable[_KT]: return self.data.keys() @@ -27,11 +30,11 @@ def __getitem__(self, __k: _KT) -> _VT: return self.data[__k] -kt1: KeysAndGetItem[int, str] = KeysAndGetItem() +kt1: KeysAndGetItem[int, str] = KeysAndGetItem({0: ""}) assert_type(dict(kt1), Dict[int, str]) dict(kt1, arg="a") # type: ignore -kt2: KeysAndGetItem[str, int] = KeysAndGetItem() +kt2: KeysAndGetItem[str, int] = KeysAndGetItem({"": 0}) assert_type(dict(kt2, arg=1), Dict[str, int]) From 80d063c7a9399e84ebfb4bdf3faaa350bc4093b3 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 12 Feb 2023 12:00:31 -0500 Subject: [PATCH 5/6] PR comments and align testcase configs more with the other two --- pyrightconfig.json | 4 ++-- pyrightconfig.stricter.json | 4 ++-- pyrightconfig.testcases.json | 14 +++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index 704a672b92a9..c44602107c30 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -19,12 +19,12 @@ // Extra strict settings "reportCallInDefaultInitializer": "error", "reportImplicitStringConcatenation": "error", - "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, - // Too strict and has no effect in stubs + // No effect in stubs "reportMissingSuperCall": "none", + "reportUninitializedInstanceVariable": "none", // stdlib stubs trigger reportShadowedImports "reportShadowedImports": "none", // Stubs are allowed to use private variables diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index a46fd63f4eef..80f5e6f6248a 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -80,12 +80,12 @@ // Extra strict settings "reportCallInDefaultInitializer": "error", "reportImplicitStringConcatenation": "error", - "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", // Leave "type: ignore" comments to mypy "enableTypeIgnoreComments": false, - // Too strict and has no effect in stubs + // No effect in stubs "reportMissingSuperCall": "none", + "reportUninitializedInstanceVariable": "none", // stdlib stubs trigger reportShadowedImports "reportShadowedImports": "none", // Stubs are allowed to use private variables diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json index 38c1600a62ed..059df46cc608 100644 --- a/pyrightconfig.testcases.json +++ b/pyrightconfig.testcases.json @@ -8,20 +8,24 @@ "typeCheckingMode": "strict", // Extra strict settings "reportShadowedImports": "error", // Don't accidentally name a file something that shadows stdlib - "reportCallInDefaultInitializer": "error", "reportImplicitStringConcatenation": "error", - "reportPropertyTypeMismatch": "error", "reportUninitializedInstanceVariable": "error", "reportUnnecessaryTypeIgnoreComment": "error", - // Using unspecific "type ignore" comments in test_cases. + // Using unspecific `type: ignore` comments in test_cases. // See https://github.com/python/typeshed/pull/8083 "enableTypeIgnoreComments": true, + // If a test case uses this anti-pattern, there's likely a reason and annoying to `type: ignore`. + // Let flake8-bugbear flag it (B006) + "reportCallInDefaultInitializer": "none", // Too strict and not needed for type testing "reportMissingSuperCall": "none", - // Stubs don't need the actual modules to be installed - "reportMissingModuleSource": "none", // Stubs are allowed to use private variables. We may want to test those. "reportPrivateUsage": "none", + // Stubs don't need the actual modules to be installed + "reportMissingModuleSource": "none", + // Incompatible property type mismatches may be out of typeshed's control + // when they are inherited from the implementation. + "reportPropertyTypeMismatch": "none", // isinstance checks are still needed when validating inputs outside of typeshed's control "reportUnnecessaryIsInstance": "none", // The name of the self/cls parameter is out of typeshed's control. From e3a4100c97b02fd6314beb290727e4ff33cb792d Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 12 Feb 2023 16:35:25 -0500 Subject: [PATCH 6/6] Update test_cases/stdlib/builtins/check_dict.py Co-authored-by: Alex Waygood --- test_cases/stdlib/builtins/check_dict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_cases/stdlib/builtins/check_dict.py b/test_cases/stdlib/builtins/check_dict.py index 66c9e9a1add0..731662e630e4 100644 --- a/test_cases/stdlib/builtins/check_dict.py +++ b/test_cases/stdlib/builtins/check_dict.py @@ -20,7 +20,7 @@ class KeysAndGetItem(Generic[_KT, _VT]): data: dict[_KT, _VT] - def __init__(self, data: dict[_KT, _VT]): + def __init__(self, data: dict[_KT, _VT]) -> None: self.data = data def keys(self) -> Iterable[_KT]: