mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Further improve and simplify pyright configuration (#9714)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -20,6 +20,9 @@ _VT = TypeVar("_VT")
|
||||
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()
|
||||
|
||||
@@ -27,11 +30,11 @@ class KeysAndGetItem(Generic[_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])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user