Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify pyrightconfig.json , add missing comments and extra strict settings in all pyright configs #9714

Merged
merged 6 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,24 @@
// 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
"reportCallInDefaultInitializer": "error",
"reportImplicitStringConcatenation": "error",
"reportUnnecessaryTypeIgnoreComment": "error",
// Leave "type: ignore" comments to mypy
"enableTypeIgnoreComments": false,
// No effect in stubs
"reportMissingSuperCall": "none",
"reportUninitializedInstanceVariable": "none",
// 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
Expand Down
12 changes: 10 additions & 2 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@
"stubs/vobject",
],
"typeCheckingMode": "strict",
// TODO: Complete incomplete stubs
"reportIncompleteStub": "none",
// Extra strict settings
"reportCallInDefaultInitializer": "error",
"reportImplicitStringConcatenation": "error",
"reportUnnecessaryTypeIgnoreComment": "error",
// Leave "type: ignore" comments to mypy
"enableTypeIgnoreComments": false,
// No effect in stubs
"reportMissingSuperCall": "none",
"reportUninitializedInstanceVariable": "none",
// stdlib stubs trigger reportShadowedImports
"reportShadowedImports": "none",
// 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
Expand Down
21 changes: 17 additions & 4 deletions pyrightconfig.testcases.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
"stubs/**/@tests/test_cases"
],
"typeCheckingMode": "strict",
// Using unspecific "type ignore" comments in test_cases.
// Extra strict settings
"reportShadowedImports": "error", // Don't accidentally name a file something that shadows stdlib
"reportImplicitStringConcatenation": "error",
"reportUninitializedInstanceVariable": "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",
"reportMissingModuleSource": "none",
// 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 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.
Expand Down
7 changes: 5 additions & 2 deletions test_cases/stdlib/builtins/check_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
class KeysAndGetItem(Generic[_KT, _VT]):
data: dict[_KT, _VT]

def __init__(self, data: dict[_KT, _VT]) -> None:
self.data = data

def keys(self) -> Iterable[_KT]:
return self.data.keys()

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])


Expand Down