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 4 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",
"reportUninitializedInstanceVariable": "error",
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
"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
"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",
"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
"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
13 changes: 11 additions & 2 deletions pyrightconfig.testcases.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
"stubs/**/@tests/test_cases"
],
"typeCheckingMode": "strict",
// Extra strict settings
"reportShadowedImports": "error", // Don't accidentally name a file something that shadows stdlib
"reportCallInDefaultInitializer": "error",
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
"reportImplicitStringConcatenation": "error",
"reportPropertyTypeMismatch": "error",
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
"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",
// 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",
// isinstance checks are still needed when validating inputs outside of typeshed's control
"reportUnnecessaryIsInstance": "none",
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]):
Avasam marked this conversation as resolved.
Show resolved Hide resolved
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