From a66b42e2d3e7ef0d6dc713c9bc6643d3603ce0f9 Mon Sep 17 00:00:00 2001 From: MylesBartlett Date: Tue, 12 Nov 2024 15:43:47 +0000 Subject: [PATCH] Add docstrings to Vec where missing. Sample indices instead of sampling elements in Vec.choose_multiple. --- .pre-commit-config.yaml | 4 +- pyproject.toml | 20 +- pyrightconfig.json | 1 - pyrightconfig.schema.json | 1519 ++++++++++++++++++------------------- requirements-dev.lock | 3 + serox/iter.py | 157 ++++ serox/option.py | 6 +- serox/vec.py | 204 ++++- 8 files changed, 1122 insertions(+), 792 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8ff7db1..5f6571f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: language: system pass_filenames: false require_serial: true - stages: [commit, merge-commit, push, manual] + stages: [pre-commit, pre-merge-commit, pre-push, manual] - id: make-test name: Make test @@ -33,4 +33,4 @@ repos: language: system pass_filenames: false require_serial: true - stages: [commit, merge-commit, push, manual] + stages: [pre-commit, pre-merge-commit, pre-push, manual] diff --git a/pyproject.toml b/pyproject.toml index 9a74b76..b53be22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,20 @@ requires-python = ">= 3.12" build-backend = "hatchling.build" requires = ["hatchling"] +[dependency-groups] +dev = [ + "basedpyright>=1.21.0", + "codespell>=2.3.0", + "pre-commit>=4.0.1", + "pydoclint>=0.5.9", + "pytest-cov>=6.0.0", + "pytest>=8.3.3", + "ruff>=0.7.3", +] + +[tool.uv] +managed = true + [tool.rye] dev-dependencies = [ "pytest>=8.3.1", @@ -141,4 +155,8 @@ ignore_errors = true fail_under = 70 [tool.coverage.run] -branch = true \ No newline at end of file +branch = true + +[tool.basedpyright] +typeCheckingMode = "all" +reportIgnoreCommentWithoutRule = "error" \ No newline at end of file diff --git a/pyrightconfig.json b/pyrightconfig.json index a1fb535..78c3037 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,5 +1,4 @@ { - "$schema": "pyrightconfig.schema.json", "include": [ "serox/**" ], diff --git a/pyrightconfig.schema.json b/pyrightconfig.schema.json index cd2d2a7..4e74a95 100644 --- a/pyrightconfig.schema.json +++ b/pyrightconfig.schema.json @@ -1,762 +1,761 @@ { - "$schema": "http://json-schema.org/draft-07/schema#", - "description": "Pyright Configuration Schema", - "allowComments": true, - "allowTrailingCommas": true, - "type": "object", - "definitions": { - "diagnostic": { - "anyOf": [ - { - "type": "boolean" - }, - { - "type": "string", - "enum": [ - "none", - "information", - "warning", - "error" - ] - } - ] - } - }, - "properties": { - "include": { - "$id": "#/properties/include", - "type": "array", - "title": "Files and directories included in type analysis", - "items": { - "$id": "#/properties/include/items", - "type": "string", - "title": "File or directory to include in type analysis", - "pattern": "^(.*)$" - } - }, - "exclude": { - "$id": "#/properties/exclude", - "type": "array", - "title": "Files and directories excluded from type analysis", - "items": { - "$id": "#/properties/exclude/items", - "type": "string", - "title": "File or directory to exclude from type analysis", - "pattern": "^(.*)$" - } - }, - "ignore": { - "$id": "#/properties/ignore", - "type": "array", - "title": "Files and directories whose diagnostics are suppressed", - "items": { - "$id": "#/properties/ignore/items", - "type": "string", - "title": "File or directory where diagnostics should be suppressed", - "pattern": "^(.*)$" - } - }, - "strict": { - "$id": "#/properties/strict", - "type": "array", - "title": "Files and directories that should use 'strict' type checking rules", - "items": { - "$id": "#/properties/strict/items", - "type": "string", - "title": "File or directory that should use 'strict' type checking rules", - "pattern": "^(.*)$" - } - }, - "defineConstant": { - "$id": "#/properties/defineConstant", - "type": "object", - "title": "Identifiers that should be treated as constants", - "properties": {}, - "additionalProperties": { - "type": [ - "string", - "boolean" - ], - "title": "Value of constant (boolean or string)" - } - }, - "typeCheckingMode": { - "$id": "#/properties/typeCheckingMode", - "type": "string", - "enum": [ - "off", - "basic", - "standard", - "strict" - ], - "title": "Specifies the default rule set to use for type checking", - "default": "standard" - }, - "useLibraryCodeForTypes": { - "$id": "#/properties/useLibraryCodeForTypes", - "type": "boolean", - "title": "Use library implementations to extract type information when type stub is not present", - "default": true - }, - "typeshedPath": { - "$id": "#/properties/typeshedPath", - "type": "string", - "title": "Path to directory containing typeshed type stub files", - "default": "", - "pattern": "^(.*)$" - }, - "stubPath": { - "$id": "#/properties/stubPath", - "type": "string", - "title": "Path to directory containing custom type stub files", - "default": "", - "examples": [ - "src/typestubs" - ], - "pattern": "^(.*)$" - }, - "disableBytesTypePromotions": { - "$id": "#/properties/disableBytesTypePromotions", - "type": "boolean", - "title": "Do not treat `bytearray` and `memoryview` as implicit subtypes of `bytes`", - "default": false - }, - "strictListInference": { - "$id": "#/properties/strictListInference", - "type": "boolean", - "title": "Infer strict types for list expressions", - "default": false - }, - "strictSetInference": { - "$id": "#/properties/strictSetInference", - "type": "boolean", - "title": "Infer strict types for set expressions", - "default": false - }, - "strictDictionaryInference": { - "$id": "#/properties/strictDictionaryInference", - "type": "boolean", - "title": "Infer strict types for dictionary expressions", - "default": false - }, - "analyzeUnannotatedFunctions": { - "$id": "#/properties/analyzeUnannotatedFunctions", - "type": "boolean", - "title": "Analyze and report diagnostics for functions that have no annotations", - "default": true - }, - "strictParameterNoneValue": { - "$id": "#/properties/strictParameterNoneValue", - "type": "boolean", - "title": "Allow implicit Optional when default parameter value is None", - "default": true - }, - "enableExperimentalFeatures": { - "$id": "#/properties/enableExperimentalFeatures", - "type": "boolean", - "title": "Enable the use of experimental features that are not part of the Python typing spec", - "default": false - }, - "enableTypeIgnoreComments": { - "$id": "#/properties/enableTypeIgnoreComments", - "type": "boolean", - "title": "Allow \"# type: ignore\" comments", - "default": true - }, - "deprecateTypingAliases": { - "$id": "#/properties/deprecateTypingAliases", - "type": "boolean", - "title": "Treat typing-specific aliases to standard types as deprecated", - "default": false - }, - "reportGeneralTypeIssues": { - "$id": "#/properties/reportGeneralTypeIssues", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of general type issues", - "default": "error" - }, - "reportPropertyTypeMismatch": { - "$id": "#/properties/reportPropertyTypeMismatch", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of property getter/setter type mismatches", - "default": "none" - }, - "reportFunctionMemberAccess": { - "$id": "#/properties/reportFunctionMemberAccess", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of member accesses on function objects", - "default": "error" - }, - "reportMissingImports": { - "$id": "#/properties/reportMissingImports", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of imports that cannot be resolved", - "default": "error" - }, - "reportMissingModuleSource": { - "$id": "#/properties/reportMissingModuleSource", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of imports that cannot be resolved to source files", - "default": "warning" - }, - "reportInvalidTypeForm": { - "$id": "#/properties/reportInvalidTypeForm", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of type expressions that use an invalid form", - "default": "warning" - }, - "reportMissingTypeStubs": { - "$id": "#/properties/reportMissingTypeStubs", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of imports that cannot be resolved to type stub files", - "default": "warning" - }, - "reportImportCycles": { - "$id": "#/properties/reportImportCycles", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of module imports that create cycles in import graph", - "default": "none" - }, - "reportUnusedImport": { - "$id": "#/properties/reportUnusedImport", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of imported symbols that are not referenced within the source file", - "default": "none" - }, - "reportUnusedClass": { - "$id": "#/properties/reportUnusedClass", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of private classes that are not accessed", - "default": "none" - }, - "reportUnusedFunction": { - "$id": "#/properties/reportUnusedFunction", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of private functions or methods that are not accessed", - "default": "none" - }, - "reportUnusedVariable": { - "$id": "#/properties/reportUnusedVariable", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of local variables that are not accessed", - "default": "none" - }, - "reportDuplicateImport": { - "$id": "#/properties/reportDuplicateImport", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of symbols or modules that are imported more than once", - "default": "none" - }, - "reportWildcardImportFromLibrary": { - "$id": "#/properties/reportWildcardImportFromLibrary", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of wildcard import from external library", - "default": "warning" - }, - "reportAbstractUsage": { - "$id": "#/properties/reportAbstractUsage", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempted instantiation of abstract class", - "default": "error" - }, - "reportArgumentType": { - "$id": "#/properties/reportArgumentType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of incompatible argument type", - "default": "error" - }, - "reportAssertTypeFailure": { - "$id": "#/properties/reportAssertTypeFailure", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of type mismatch detected by typing.assert_type call", - "default": "error" - }, - "reportAssignmentType": { - "$id": "#/properties/reportAssignmentType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of type incompatibilities for assignments", - "default": "error" - }, - "reportAttributeAccessIssue": { - "$id": "#/properties/reportAttributeAccessIssue", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of issues related to attribute accesses", - "default": "error" - }, - "reportCallIssue": { - "$id": "#/properties/reportCallIssue", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of issues related to call expressions and arguments", - "default": "error" - }, - "reportInconsistentOverload": { - "$id": "#/properties/reportInconsistentOverload", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of inconsistencies between function overload signatures", - "default": "error" - }, - "reportIndexIssue": { - "$id": "#/properties/reportIndexIssue", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of issues related to index operations and expressions", - "default": "error" - }, - "reportInvalidTypeArguments": { - "$id": "#/properties/reportInvalidTypeArguments", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of invalid type argument usage", - "default": "error" - }, - "reportNoOverloadImplementation": { - "$id": "#/properties/reportNoOverloadImplementation", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of an overloaded function or method with a missing implementation", - "default": "error" - }, - "reportOperatorIssue": { - "$id": "#/properties/reportOperatorIssue", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of diagnostics related to unary and binary operators", - "default": "error" - }, - "reportOptionalSubscript": { - "$id": "#/properties/reportOptionalSubscript", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to subscript (index) a variable with Optional type", - "default": "error" - }, - "reportOptionalMemberAccess": { - "$id": "#/properties/reportOptionalMemberAccess", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to access a member of a variable with Optional type", - "default": "error" - }, - "reportOptionalCall": { - "$id": "#/properties/reportOptionalCall", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to call a variable with Optional type", - "default": "error" - }, - "reportOptionalIterable": { - "$id": "#/properties/reportOptionalIterable", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to use an Optional type as an iterable value", - "default": "error" - }, - "reportOptionalContextManager": { - "$id": "#/properties/reportOptionalContextManager", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to use an Optional type as a parameter to a with statement", - "default": "error" - }, - "reportOptionalOperand": { - "$id": "#/properties/reportOptionalOperand", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to use an Optional type as an operand for a binary or unary operator", - "default": "error" - }, - "reportRedeclaration": { - "$id": "#/properties/reportRedeclaration", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to declare the type of a symbol multiple times", - "default": "error" - }, - "reportReturnType": { - "$id": "#/properties/reportReturnType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of function return type incompatibility", - "default": "error" - }, - "reportTypedDictNotRequiredAccess": { - "$id": "#/properties/reportTypedDictNotRequiredAccess", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to access a non-required key in a TypedDict without a check for its presence", - "default": "error" - }, - "reportUntypedFunctionDecorator": { - "$id": "#/properties/reportUntypedFunctionDecorator", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of function decorators without type annotations, which obscure function types", - "default": "none" - }, - "reportUntypedClassDecorator": { - "$id": "#/properties/reportUntypedClassDecorator", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of class decorators without type annotations, which obscure class types", - "default": "none" - }, - "reportUntypedBaseClass": { - "$id": "#/properties/reportUntypedBaseClass", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of a base class of an unknown type, which obscures most type checking for the class", - "default": "none" - }, - "reportUntypedNamedTuple": { - "$id": "#/properties/reportUntypedNamedTuple", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of a named tuple definition that does not contain type information", - "default": "none" - }, - "reportPrivateUsage": { - "$id": "#/properties/reportPrivateUsage", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of private variables and functions used outside of the owning class or module and usage of protected members outside of subclasses", - "default": "none" - }, - "reportTypeCommentUsage": { - "$id": "#/properties/reportTypeCommentUsage", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of deprecated type comment usage", - "default": "none" - }, - "reportPrivateImportUsage": { - "$id": "#/properties/reportPrivateImportUsage", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of improper usage of symbol imported from a \"py.typed\" module that is not re-exported from that module", - "default": "error" - }, - "reportConstantRedefinition": { - "$id": "#/properties/reportConstantRedefinition", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to redefine variables that are in all-caps", - "default": "none" - }, - "reportDeprecated": { - "$id": "#/properties/reportDeprecated", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of use of deprecated class or function", - "default": "none" - }, - "reportIncompatibleMethodOverride": { - "$id": "#/properties/reportIncompatibleMethodOverride", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of method overrides in subclasses that redefine the method in an incompatible way", - "default": "error" - }, - "reportIncompatibleVariableOverride": { - "$id": "#/properties/reportIncompatibleVariableOverride", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of overrides in subclasses that redefine a variable in an incompatible way", - "default": "error" - }, - "reportInconsistentConstructor": { - "$id": "#/properties/reportInconsistentConstructor", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of __init__ and __new__ methods whose signatures are inconsistent", - "default": "none" - }, - "reportOverlappingOverload": { - "$id": "#/properties/reportOverlappingOverload", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of function overloads that overlap in signature and obscure each other or do not agree on return type", - "default": "error" - }, - "reportPossiblyUnboundVariable": { - "$id": "#/properties/reportPossiblyUnboundVariable", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to use variable that is possibly unbound on some code paths", - "default": "error" - }, - "reportMissingSuperCall": { - "$id": "#/properties/reportMissingSuperCall", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of missing call to parent class for inherited `__init__` methods", - "default": "none" - }, - "reportUninitializedInstanceVariable": { - "$id": "#/properties/reportUninitializedInstanceVariable", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of instance variables that are not initialized in the constructor", - "default": "none" - }, - "reportInvalidStringEscapeSequence": { - "$id": "#/properties/reportInvalidStringEscapeSequence", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of invalid escape sequences used within string literals", - "default": "warning" - }, - "reportUnknownParameterType": { - "$id": "#/properties/reportUnknownParameterType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting input and return parameters whose types are unknown", - "default": "none" - }, - "reportUnknownArgumentType": { - "$id": "#/properties/reportUnknownArgumentType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting argument expressions whose types are unknown", - "default": "none" - }, - "reportUnknownLambdaType": { - "$id": "#/properties/reportUnknownLambdaType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting input and return parameters for lambdas whose types are unknown", - "default": "none" - }, - "reportUnknownVariableType": { - "$id": "#/properties/reportUnknownVariableType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting local variables whose types are unknown", - "default": "none" - }, - "reportUnknownMemberType": { - "$id": "#/properties/reportUnknownMemberType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting class and instance variables whose types are unknown", - "default": "none" - }, - "reportMissingParameterType": { - "$id": "#/properties/reportMissingParameterType", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting input parameters that are missing a type annotation", - "default": "none" - }, - "reportMissingTypeArgument": { - "$id": "#/properties/reportMissingTypeArgument", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting generic class reference with missing type arguments", - "default": "none" - }, - "reportInvalidTypeVarUse": { - "$id": "#/properties/reportInvalidTypeVarUse", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting improper use of type variables within function signatures", - "default": "warning" - }, - "reportCallInDefaultInitializer": { - "$id": "#/properties/reportCallInDefaultInitializer", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting usage of function calls within a default value initializer expression", - "default": "none" - }, - "reportUnnecessaryIsInstance": { - "$id": "#/properties/reportUnnecessaryIsInstance", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting calls to 'isinstance' or 'issubclass' where the result is statically determined to be always true", - "default": "none" - }, - "reportUnnecessaryCast": { - "$id": "#/properties/reportUnnecessaryCast", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting calls to 'cast' that are unnecessary", - "default": "none" - }, - "reportUnnecessaryComparison": { - "$id": "#/properties/reportUnnecessaryComparison", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting the use of '==' or '!=' comparisons that are unnecessary", - "default": "none" - }, - "reportUnnecessaryContains": { - "$id": "#/properties/reportUnnecessaryContains", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting the use of 'in' operations that are unnecessary", - "default": "none" - }, - "reportAssertAlwaysTrue": { - "$id": "#/properties/reportAssertAlwaysTrue", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting assert expressions that will always evaluate to true", - "default": "warning" - }, - "reportSelfClsParameterName": { - "$id": "#/properties/reportSelfClsParameterName", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting missing or misnamed self parameters", - "default": "warning" - }, - "reportImplicitStringConcatenation": { - "$id": "#/properties/reportImplicitStringConcatenation", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting usage of implicit concatenation of string literals", - "default": "none" - }, - "reportUnboundVariable": { - "$id": "#/properties/reportUnboundVariable", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to use an unbound variable", - "default": "error" - }, - "reportUndefinedVariable": { - "$id": "#/properties/reportUndefinedVariable", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of attempts to use an undefined variable", - "default": "error" - }, - "reportInvalidStubStatement": { - "$id": "#/properties/reportInvalidStubStatement", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of type stub statements that do not conform to PEP 484", - "default": "none" - }, - "reportIncompleteStub": { - "$id": "#/properties/reportIncompleteStub", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of incomplete type stubs that declare a module-level __getattr__ function", - "default": "none" - }, - "reportUnsupportedDunderAll": { - "$id": "#/properties/reportUnsupportedDunderAll", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of unsupported operations performed on __all__", - "default": "warning" - }, - "reportUnusedCallResult": { - "$id": "#/properties/reportUnusedCallResult", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of call expressions whose results are not consumed", - "default": "none" - }, - "reportUnusedCoroutine": { - "$id": "#/properties/reportUnusedCoroutine", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of call expressions that returns Coroutine whose results are not consumed", - "default": "error" - }, - "reportUnusedExcept": { - "$id": "#/properties/reportUnusedExcept", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of unreachable except clauses", - "default": "error" - }, - "reportUnusedExpression": { - "$id": "#/properties/reportUnusedExpression", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of simple expressions whose value is not used in any way", - "default": "warning" - }, - "reportUnnecessaryTypeIgnoreComment": { - "$id": "#/properties/reportUnnecessaryTypeIgnoreComment", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of '# type: ignore' comments that have no effect'", - "default": "none" - }, - "reportMatchNotExhaustive": { - "$id": "#/properties/reportMatchNotExhaustive", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of 'match' statements that do not exhaustively match all possible values", - "default": "none" - }, - "reportShadowedImports": { - "$id": "#/properties/reportShadowedImports", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting of shadowed imports of stdlib modules", - "default": "none" - }, - "reportImplicitOverride": { - "$id": "#/properties/reportImplicitOverride", - "$ref": "#/definitions/diagnostic", - "title": "Controls reporting overridden methods that are missing an `@override` decorator", - "default": "none" - }, - "extraPaths": { - "$id": "#/properties/extraPaths", - "type": "array", - "title": "Additional import search resolution paths", - "items": { - "$id": "#/properties/extraPaths/items", - "type": "string", - "title": "Additional import search resolution path", - "default": "", - "pattern": "^(.*)$" - } - }, - "pythonVersion": { - "$id": "#/properties/pythonVersion", - "type": "string", - "title": "Python version to assume during type analysis", - "default": "", - "examples": [ - "3.7" - ], - "pattern": "^3\\.[0-9]+$" - }, - "pythonPlatform": { - "$id": "#/properties/pythonPlatform", - "type": "string", - "title": "Python platform to assume during type analysis", - "default": "", - "examples": [ - "Linux" - ], - "pattern": "^(Linux|Windows|Darwin|All)$" - }, - "venvPath": { - "$id": "#/properties/venvPath", - "type": "string", - "title": "Path to directory containing a folder of virtual environments", - "default": "", - "pattern": "^(.*)$" - }, - "venv": { - "$id": "#/properties/venv", - "type": "string", - "title": "Name of virtual environment subdirectory within venvPath", - "default": "", - "examples": [ - "python37" - ], - "pattern": "^(.*)$" - }, - "verboseOutput": { - "$id": "#/properties/verboseOutput", - "type": "boolean", - "title": "Output verbose logging", - "default": false - }, - "executionEnvironments": { - "$id": "#/properties/executionEnvironments", - "type": "array", - "title": "Analysis settings to use for specified subdirectories of code", - "items": { - "$id": "#/properties/executionEnvironments/items", - "type": "object", - "title": "Analysis settings to use for specified subdirectories of code", - "required": [ - "root" - ], - "properties": { - "root": { - "$id": "#/properties/executionEnvironments/items/properties/root", - "type": "string", - "title": "Path to code subdirectory to which these settings apply", - "default": "", - "pattern": "^(.*)$" - }, - "extraPaths": { - "$id": "#/properties/executionEnvironments/items/properties/extraPaths", - "type": "array", - "title": "Additional import search resolution paths", - "items": { - "$id": "#/properties/executionEnvironments/items/properties/extraPaths/items", - "type": "string", - "title": "Additional import search resolution path", - "default": "", - "pattern": "^(.*)$" - } - }, - "pythonVersion": { - "$id": "#/properties/executionEnvironments/items/properties/pythonVersion", - "type": "string", - "title": "Python version to assume during type analysis", - "default": "", - "examples": [ - "3.7" - ], - "pattern": "^3\\.[0-9]+$" - }, - "pythonPlatform": { - "$id": "#/properties/executionEnvironments/items/properties/pythonPlatform", - "type": "string", - "title": "Python platform to assume during type analysis", - "default": "", - "examples": [ - "Linux" - ], - "pattern": "^(Linux|Windows|Darwin|All)$" - } - } - } - } - } + "description": "Pyright Configuration Schema", + "allowComments": true, + "allowTrailingCommas": true, + "type": "object", + "definitions": { + "diagnostic": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string", + "enum": [ + "none", + "information", + "warning", + "error" + ] + } + ] + } + }, + "properties": { + "include": { + "$id": "#/properties/include", + "type": "array", + "title": "Files and directories included in type analysis", + "items": { + "$id": "#/properties/include/items", + "type": "string", + "title": "File or directory to include in type analysis", + "pattern": "^(.*)$" + } + }, + "exclude": { + "$id": "#/properties/exclude", + "type": "array", + "title": "Files and directories excluded from type analysis", + "items": { + "$id": "#/properties/exclude/items", + "type": "string", + "title": "File or directory to exclude from type analysis", + "pattern": "^(.*)$" + } + }, + "ignore": { + "$id": "#/properties/ignore", + "type": "array", + "title": "Files and directories whose diagnostics are suppressed", + "items": { + "$id": "#/properties/ignore/items", + "type": "string", + "title": "File or directory where diagnostics should be suppressed", + "pattern": "^(.*)$" + } + }, + "strict": { + "$id": "#/properties/strict", + "type": "array", + "title": "Files and directories that should use 'strict' type checking rules", + "items": { + "$id": "#/properties/strict/items", + "type": "string", + "title": "File or directory that should use 'strict' type checking rules", + "pattern": "^(.*)$" + } + }, + "defineConstant": { + "$id": "#/properties/defineConstant", + "type": "object", + "title": "Identifiers that should be treated as constants", + "properties": {}, + "additionalProperties": { + "type": [ + "string", + "boolean" + ], + "title": "Value of constant (boolean or string)" + } + }, + "typeCheckingMode": { + "$id": "#/properties/typeCheckingMode", + "type": "string", + "enum": [ + "off", + "basic", + "standard", + "strict" + ], + "title": "Specifies the default rule set to use for type checking", + "default": "standard" + }, + "useLibraryCodeForTypes": { + "$id": "#/properties/useLibraryCodeForTypes", + "type": "boolean", + "title": "Use library implementations to extract type information when type stub is not present", + "default": true + }, + "typeshedPath": { + "$id": "#/properties/typeshedPath", + "type": "string", + "title": "Path to directory containing typeshed type stub files", + "default": "", + "pattern": "^(.*)$" + }, + "stubPath": { + "$id": "#/properties/stubPath", + "type": "string", + "title": "Path to directory containing custom type stub files", + "default": "", + "examples": [ + "src/typestubs" + ], + "pattern": "^(.*)$" + }, + "disableBytesTypePromotions": { + "$id": "#/properties/disableBytesTypePromotions", + "type": "boolean", + "title": "Do not treat `bytearray` and `memoryview` as implicit subtypes of `bytes`", + "default": false + }, + "strictListInference": { + "$id": "#/properties/strictListInference", + "type": "boolean", + "title": "Infer strict types for list expressions", + "default": false + }, + "strictSetInference": { + "$id": "#/properties/strictSetInference", + "type": "boolean", + "title": "Infer strict types for set expressions", + "default": false + }, + "strictDictionaryInference": { + "$id": "#/properties/strictDictionaryInference", + "type": "boolean", + "title": "Infer strict types for dictionary expressions", + "default": false + }, + "analyzeUnannotatedFunctions": { + "$id": "#/properties/analyzeUnannotatedFunctions", + "type": "boolean", + "title": "Analyze and report diagnostics for functions that have no annotations", + "default": true + }, + "strictParameterNoneValue": { + "$id": "#/properties/strictParameterNoneValue", + "type": "boolean", + "title": "Allow implicit Optional when default parameter value is None", + "default": true + }, + "enableExperimentalFeatures": { + "$id": "#/properties/enableExperimentalFeatures", + "type": "boolean", + "title": "Enable the use of experimental features that are not part of the Python typing spec", + "default": false + }, + "enableTypeIgnoreComments": { + "$id": "#/properties/enableTypeIgnoreComments", + "type": "boolean", + "title": "Allow \"# type: ignore\" comments", + "default": true + }, + "deprecateTypingAliases": { + "$id": "#/properties/deprecateTypingAliases", + "type": "boolean", + "title": "Treat typing-specific aliases to standard types as deprecated", + "default": false + }, + "reportGeneralTypeIssues": { + "$id": "#/properties/reportGeneralTypeIssues", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of general type issues", + "default": "error" + }, + "reportPropertyTypeMismatch": { + "$id": "#/properties/reportPropertyTypeMismatch", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of property getter/setter type mismatches", + "default": "none" + }, + "reportFunctionMemberAccess": { + "$id": "#/properties/reportFunctionMemberAccess", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of member accesses on function objects", + "default": "error" + }, + "reportMissingImports": { + "$id": "#/properties/reportMissingImports", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of imports that cannot be resolved", + "default": "error" + }, + "reportMissingModuleSource": { + "$id": "#/properties/reportMissingModuleSource", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of imports that cannot be resolved to source files", + "default": "warning" + }, + "reportInvalidTypeForm": { + "$id": "#/properties/reportInvalidTypeForm", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of type expressions that use an invalid form", + "default": "warning" + }, + "reportMissingTypeStubs": { + "$id": "#/properties/reportMissingTypeStubs", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of imports that cannot be resolved to type stub files", + "default": "warning" + }, + "reportImportCycles": { + "$id": "#/properties/reportImportCycles", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of module imports that create cycles in import graph", + "default": "none" + }, + "reportUnusedImport": { + "$id": "#/properties/reportUnusedImport", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of imported symbols that are not referenced within the source file", + "default": "none" + }, + "reportUnusedClass": { + "$id": "#/properties/reportUnusedClass", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of private classes that are not accessed", + "default": "none" + }, + "reportUnusedFunction": { + "$id": "#/properties/reportUnusedFunction", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of private functions or methods that are not accessed", + "default": "none" + }, + "reportUnusedVariable": { + "$id": "#/properties/reportUnusedVariable", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of local variables that are not accessed", + "default": "none" + }, + "reportDuplicateImport": { + "$id": "#/properties/reportDuplicateImport", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of symbols or modules that are imported more than once", + "default": "none" + }, + "reportWildcardImportFromLibrary": { + "$id": "#/properties/reportWildcardImportFromLibrary", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of wildcard import from external library", + "default": "warning" + }, + "reportAbstractUsage": { + "$id": "#/properties/reportAbstractUsage", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempted instantiation of abstract class", + "default": "error" + }, + "reportArgumentType": { + "$id": "#/properties/reportArgumentType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of incompatible argument type", + "default": "error" + }, + "reportAssertTypeFailure": { + "$id": "#/properties/reportAssertTypeFailure", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of type mismatch detected by typing.assert_type call", + "default": "error" + }, + "reportAssignmentType": { + "$id": "#/properties/reportAssignmentType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of type incompatibilities for assignments", + "default": "error" + }, + "reportAttributeAccessIssue": { + "$id": "#/properties/reportAttributeAccessIssue", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of issues related to attribute accesses", + "default": "error" + }, + "reportCallIssue": { + "$id": "#/properties/reportCallIssue", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of issues related to call expressions and arguments", + "default": "error" + }, + "reportInconsistentOverload": { + "$id": "#/properties/reportInconsistentOverload", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of inconsistencies between function overload signatures", + "default": "error" + }, + "reportIndexIssue": { + "$id": "#/properties/reportIndexIssue", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of issues related to index operations and expressions", + "default": "error" + }, + "reportInvalidTypeArguments": { + "$id": "#/properties/reportInvalidTypeArguments", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of invalid type argument usage", + "default": "error" + }, + "reportNoOverloadImplementation": { + "$id": "#/properties/reportNoOverloadImplementation", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of an overloaded function or method with a missing implementation", + "default": "error" + }, + "reportOperatorIssue": { + "$id": "#/properties/reportOperatorIssue", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of diagnostics related to unary and binary operators", + "default": "error" + }, + "reportOptionalSubscript": { + "$id": "#/properties/reportOptionalSubscript", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to subscript (index) a variable with Optional type", + "default": "error" + }, + "reportOptionalMemberAccess": { + "$id": "#/properties/reportOptionalMemberAccess", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to access a member of a variable with Optional type", + "default": "error" + }, + "reportOptionalCall": { + "$id": "#/properties/reportOptionalCall", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to call a variable with Optional type", + "default": "error" + }, + "reportOptionalIterable": { + "$id": "#/properties/reportOptionalIterable", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to use an Optional type as an iterable value", + "default": "error" + }, + "reportOptionalContextManager": { + "$id": "#/properties/reportOptionalContextManager", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to use an Optional type as a parameter to a with statement", + "default": "error" + }, + "reportOptionalOperand": { + "$id": "#/properties/reportOptionalOperand", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to use an Optional type as an operand for a binary or unary operator", + "default": "error" + }, + "reportRedeclaration": { + "$id": "#/properties/reportRedeclaration", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to declare the type of a symbol multiple times", + "default": "error" + }, + "reportReturnType": { + "$id": "#/properties/reportReturnType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of function return type incompatibility", + "default": "error" + }, + "reportTypedDictNotRequiredAccess": { + "$id": "#/properties/reportTypedDictNotRequiredAccess", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to access a non-required key in a TypedDict without a check for its presence", + "default": "error" + }, + "reportUntypedFunctionDecorator": { + "$id": "#/properties/reportUntypedFunctionDecorator", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of function decorators without type annotations, which obscure function types", + "default": "none" + }, + "reportUntypedClassDecorator": { + "$id": "#/properties/reportUntypedClassDecorator", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of class decorators without type annotations, which obscure class types", + "default": "none" + }, + "reportUntypedBaseClass": { + "$id": "#/properties/reportUntypedBaseClass", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of a base class of an unknown type, which obscures most type checking for the class", + "default": "none" + }, + "reportUntypedNamedTuple": { + "$id": "#/properties/reportUntypedNamedTuple", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of a named tuple definition that does not contain type information", + "default": "none" + }, + "reportPrivateUsage": { + "$id": "#/properties/reportPrivateUsage", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of private variables and functions used outside of the owning class or module and usage of protected members outside of subclasses", + "default": "none" + }, + "reportTypeCommentUsage": { + "$id": "#/properties/reportTypeCommentUsage", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of deprecated type comment usage", + "default": "none" + }, + "reportPrivateImportUsage": { + "$id": "#/properties/reportPrivateImportUsage", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of improper usage of symbol imported from a \"py.typed\" module that is not re-exported from that module", + "default": "error" + }, + "reportConstantRedefinition": { + "$id": "#/properties/reportConstantRedefinition", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to redefine variables that are in all-caps", + "default": "none" + }, + "reportDeprecated": { + "$id": "#/properties/reportDeprecated", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of use of deprecated class or function", + "default": "none" + }, + "reportIncompatibleMethodOverride": { + "$id": "#/properties/reportIncompatibleMethodOverride", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of method overrides in subclasses that redefine the method in an incompatible way", + "default": "error" + }, + "reportIncompatibleVariableOverride": { + "$id": "#/properties/reportIncompatibleVariableOverride", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of overrides in subclasses that redefine a variable in an incompatible way", + "default": "error" + }, + "reportInconsistentConstructor": { + "$id": "#/properties/reportInconsistentConstructor", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of __init__ and __new__ methods whose signatures are inconsistent", + "default": "none" + }, + "reportOverlappingOverload": { + "$id": "#/properties/reportOverlappingOverload", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of function overloads that overlap in signature and obscure each other or do not agree on return type", + "default": "error" + }, + "reportPossiblyUnboundVariable": { + "$id": "#/properties/reportPossiblyUnboundVariable", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to use variable that is possibly unbound on some code paths", + "default": "error" + }, + "reportMissingSuperCall": { + "$id": "#/properties/reportMissingSuperCall", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of missing call to parent class for inherited `__init__` methods", + "default": "none" + }, + "reportUninitializedInstanceVariable": { + "$id": "#/properties/reportUninitializedInstanceVariable", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of instance variables that are not initialized in the constructor", + "default": "none" + }, + "reportInvalidStringEscapeSequence": { + "$id": "#/properties/reportInvalidStringEscapeSequence", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of invalid escape sequences used within string literals", + "default": "warning" + }, + "reportUnknownParameterType": { + "$id": "#/properties/reportUnknownParameterType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting input and return parameters whose types are unknown", + "default": "none" + }, + "reportUnknownArgumentType": { + "$id": "#/properties/reportUnknownArgumentType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting argument expressions whose types are unknown", + "default": "none" + }, + "reportUnknownLambdaType": { + "$id": "#/properties/reportUnknownLambdaType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting input and return parameters for lambdas whose types are unknown", + "default": "none" + }, + "reportUnknownVariableType": { + "$id": "#/properties/reportUnknownVariableType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting local variables whose types are unknown", + "default": "none" + }, + "reportUnknownMemberType": { + "$id": "#/properties/reportUnknownMemberType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting class and instance variables whose types are unknown", + "default": "none" + }, + "reportMissingParameterType": { + "$id": "#/properties/reportMissingParameterType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting input parameters that are missing a type annotation", + "default": "none" + }, + "reportMissingTypeArgument": { + "$id": "#/properties/reportMissingTypeArgument", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting generic class reference with missing type arguments", + "default": "none" + }, + "reportInvalidTypeVarUse": { + "$id": "#/properties/reportInvalidTypeVarUse", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting improper use of type variables within function signatures", + "default": "warning" + }, + "reportCallInDefaultInitializer": { + "$id": "#/properties/reportCallInDefaultInitializer", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting usage of function calls within a default value initializer expression", + "default": "none" + }, + "reportUnnecessaryIsInstance": { + "$id": "#/properties/reportUnnecessaryIsInstance", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting calls to 'isinstance' or 'issubclass' where the result is statically determined to be always true", + "default": "none" + }, + "reportUnnecessaryCast": { + "$id": "#/properties/reportUnnecessaryCast", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting calls to 'cast' that are unnecessary", + "default": "none" + }, + "reportUnnecessaryComparison": { + "$id": "#/properties/reportUnnecessaryComparison", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting the use of '==' or '!=' comparisons that are unnecessary", + "default": "none" + }, + "reportUnnecessaryContains": { + "$id": "#/properties/reportUnnecessaryContains", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting the use of 'in' operations that are unnecessary", + "default": "none" + }, + "reportAssertAlwaysTrue": { + "$id": "#/properties/reportAssertAlwaysTrue", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting assert expressions that will always evaluate to true", + "default": "warning" + }, + "reportSelfClsParameterName": { + "$id": "#/properties/reportSelfClsParameterName", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting missing or misnamed self parameters", + "default": "warning" + }, + "reportImplicitStringConcatenation": { + "$id": "#/properties/reportImplicitStringConcatenation", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting usage of implicit concatenation of string literals", + "default": "none" + }, + "reportUnboundVariable": { + "$id": "#/properties/reportUnboundVariable", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to use an unbound variable", + "default": "error" + }, + "reportUndefinedVariable": { + "$id": "#/properties/reportUndefinedVariable", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of attempts to use an undefined variable", + "default": "error" + }, + "reportInvalidStubStatement": { + "$id": "#/properties/reportInvalidStubStatement", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of type stub statements that do not conform to PEP 484", + "default": "none" + }, + "reportIncompleteStub": { + "$id": "#/properties/reportIncompleteStub", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of incomplete type stubs that declare a module-level __getattr__ function", + "default": "none" + }, + "reportUnsupportedDunderAll": { + "$id": "#/properties/reportUnsupportedDunderAll", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of unsupported operations performed on __all__", + "default": "warning" + }, + "reportUnusedCallResult": { + "$id": "#/properties/reportUnusedCallResult", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of call expressions whose results are not consumed", + "default": "none" + }, + "reportUnusedCoroutine": { + "$id": "#/properties/reportUnusedCoroutine", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of call expressions that returns Coroutine whose results are not consumed", + "default": "error" + }, + "reportUnusedExcept": { + "$id": "#/properties/reportUnusedExcept", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of unreachable except clauses", + "default": "error" + }, + "reportUnusedExpression": { + "$id": "#/properties/reportUnusedExpression", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of simple expressions whose value is not used in any way", + "default": "warning" + }, + "reportUnnecessaryTypeIgnoreComment": { + "$id": "#/properties/reportUnnecessaryTypeIgnoreComment", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of '# type: ignore' comments that have no effect'", + "default": "none" + }, + "reportMatchNotExhaustive": { + "$id": "#/properties/reportMatchNotExhaustive", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of 'match' statements that do not exhaustively match all possible values", + "default": "none" + }, + "reportShadowedImports": { + "$id": "#/properties/reportShadowedImports", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting of shadowed imports of stdlib modules", + "default": "none" + }, + "reportImplicitOverride": { + "$id": "#/properties/reportImplicitOverride", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting overridden methods that are missing an `@override` decorator", + "default": "none" + }, + "extraPaths": { + "$id": "#/properties/extraPaths", + "type": "array", + "title": "Additional import search resolution paths", + "items": { + "$id": "#/properties/extraPaths/items", + "type": "string", + "title": "Additional import search resolution path", + "default": "", + "pattern": "^(.*)$" + } + }, + "pythonVersion": { + "$id": "#/properties/pythonVersion", + "type": "string", + "title": "Python version to assume during type analysis", + "default": "", + "examples": [ + "3.7" + ], + "pattern": "^3\\.[0-9]+$" + }, + "pythonPlatform": { + "$id": "#/properties/pythonPlatform", + "type": "string", + "title": "Python platform to assume during type analysis", + "default": "", + "examples": [ + "Linux" + ], + "pattern": "^(Linux|Windows|Darwin|All)$" + }, + "venvPath": { + "$id": "#/properties/venvPath", + "type": "string", + "title": "Path to directory containing a folder of virtual environments", + "default": "", + "pattern": "^(.*)$" + }, + "venv": { + "$id": "#/properties/venv", + "type": "string", + "title": "Name of virtual environment subdirectory within venvPath", + "default": "", + "examples": [ + "python37" + ], + "pattern": "^(.*)$" + }, + "verboseOutput": { + "$id": "#/properties/verboseOutput", + "type": "boolean", + "title": "Output verbose logging", + "default": false + }, + "executionEnvironments": { + "$id": "#/properties/executionEnvironments", + "type": "array", + "title": "Analysis settings to use for specified subdirectories of code", + "items": { + "$id": "#/properties/executionEnvironments/items", + "type": "object", + "title": "Analysis settings to use for specified subdirectories of code", + "required": [ + "root" + ], + "properties": { + "root": { + "$id": "#/properties/executionEnvironments/items/properties/root", + "type": "string", + "title": "Path to code subdirectory to which these settings apply", + "default": "", + "pattern": "^(.*)$" + }, + "extraPaths": { + "$id": "#/properties/executionEnvironments/items/properties/extraPaths", + "type": "array", + "title": "Additional import search resolution paths", + "items": { + "$id": "#/properties/executionEnvironments/items/properties/extraPaths/items", + "type": "string", + "title": "Additional import search resolution path", + "default": "", + "pattern": "^(.*)$" + } + }, + "pythonVersion": { + "$id": "#/properties/executionEnvironments/items/properties/pythonVersion", + "type": "string", + "title": "Python version to assume during type analysis", + "default": "", + "examples": [ + "3.7" + ], + "pattern": "^3\\.[0-9]+$" + }, + "pythonPlatform": { + "$id": "#/properties/executionEnvironments/items/properties/pythonPlatform", + "type": "string", + "title": "Python platform to assume during type analysis", + "default": "", + "examples": [ + "Linux" + ], + "pattern": "^(Linux|Windows|Darwin|All)$" + } + } + } + } + } } diff --git a/requirements-dev.lock b/requirements-dev.lock index 0911c25..e39a8d5 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -10,6 +10,7 @@ # universal: false -e file:. +basedpyright==1.21.0 black==24.4.2 cfgv==3.4.0 # via pre-commit @@ -38,6 +39,8 @@ mypy-extensions==1.0.0 nodeenv==1.9.1 # via pre-commit # via pyright +nodejs-wheel-binaries==22.11.0 + # via basedpyright numpy==2.0.1 # via serox packaging==24.1 diff --git a/serox/iter.py b/serox/iter.py index d9004d2..675512a 100644 --- a/serox/iter.py +++ b/serox/iter.py @@ -61,6 +61,9 @@ def from_iter[P: (True_, False_)](cls, iter: Iterator[A, P], /) -> Self: ... def _identity[T](x: T) -> T: + """ + Identity function that returns the input value. + """ return x @@ -477,3 +480,157 @@ def test_par_invariance(): # shouldn't be able to combine parallel iterators with non-parallel ones # for consistent typing _ = bridge.zip(values.iter()) # pyright: ignore[reportArgumentType] + + def test_max(): + """Test the max method for iterators.""" + from .vec import Vec + + vec = Vec(1, 2, 3, 4, 5) + assert vec.iter().max() == 5 + + def test_iterator_methods(): + from .option import Null, Some + from .result import Err, Ok + from .vec import Vec + + vec = Vec(1, 2, 3, 4, 5) + iter = vec.iter() + + # Test next + assert iter.next() == Some(1) + assert iter.next() == Some(2) + + # Test nth + assert iter.nth(2) == Some(5) + assert iter.nth(1) == Null() + + # Test advance_by + iter = vec.iter() + assert iter.advance_by(3) == Ok(None) + assert iter.advance_by(3) == Err(1) + + # Test for_each + result: list[int] = [] + iter = vec.iter() + iter.for_each(lambda x: result.append(x)) + assert result == [1, 2, 3, 4, 5] + + # Test take + iter = vec.iter().take(3) + assert list(iter) == [1, 2, 3] + + # Test take_while + iter = vec.iter().take_while(lambda x: x < 4) + assert list(iter) == [1, 2, 3] + + # Test sum + assert vec.iter().sum() == 15 + + # Test product + assert vec.iter().product() == 120 + + # Test all + assert vec.iter().all(lambda x: x > 0) + assert not vec.iter().all(lambda x: x < 3) + + # Test any + assert vec.iter().any(lambda x: x == 3) + assert not vec.iter().any(lambda x: x == 6) + + # Test max + assert vec.iter().max() == 5 + + # Test min + assert vec.iter().min() == 1 + + def test_combinational_methods(): + from .option import Null, Some + from .vec import Vec + + vec1 = Vec(1, 2, 3) + vec2 = Vec(4, 5, 6) + iter1 = vec1.iter() + iter2 = vec2.iter() + + # Test zip + zipped = iter1.zip(iter2) + assert list(zipped) == [(1, 4), (2, 5), (3, 6)] + + # Test zip_longest + iter1 = vec1.iter() + iter2 = Vec(4, 5).iter() + zipped_longest = iter1.zip_longest(iter2) + assert list(zipped_longest) == [(1, 4), (2, 5), (3, Null())] + + # Test chain + iter1 = vec1.iter() + iter2 = vec2.iter() + chained = iter1.chain(iter2) + assert list(chained) == [1, 2, 3, 4, 5, 6] + + # Test map + iter = vec1.iter().map(lambda x: x * 2) + assert list(iter) == [2, 4, 6] + + # Test filter + iter = vec1.iter().filter(lambda x: x % 2 == 1) + assert list(iter) == [1, 3] + + # Test filter_map + iter = vec1.iter().filter_map(lambda x: Some(x * 2) if x % 2 == 0 else Null()) + assert list(iter) == [4] + + def test_parallel_iterators(): + from .option import Null, Some + from .result import Err, Ok + from .vec import Vec + + vec = Vec(1, 2, 3, 4, 5) + iter = vec.par_iter() + + # Test next + assert iter.next() == Some(1) + assert iter.next() == Some(2) + + # Test nth + assert iter.nth(2) == Some(5) + assert iter.nth(1) == Null() + + # Test advance_by + iter = vec.par_iter() + assert iter.advance_by(3) == Ok(None) + assert iter.advance_by(3) == Err(1) + + # Test for_each + result: list[int] = [] + iter = vec.par_iter() + iter.for_each(lambda x: result.append(x)) + assert result == [1, 2, 3, 4, 5] + + # Test take + iter = vec.par_iter().take(3) + assert list(iter) == [1, 2, 3] + + # Test take_while + iter = vec.par_iter().take_while(lambda x: x < 4) + assert list(iter) == [1, 2, 3] + + # Test sum + assert vec.par_iter().sum() == 15 + + # Test product + assert vec.par_iter().product() == 120 + + # Test all + assert vec.par_iter().all(lambda x: x > 0) + assert not vec.par_iter().all(lambda x: x < 3) + + # Test any + assert vec.par_iter().any(lambda x: x == 3) + assert not vec.par_iter().any(lambda x: x == 6) + + # Test max + assert vec.par_iter().max() == 5 + + # Test min + assert vec.par_iter().min() == 1 diff --git a/serox/option.py b/serox/option.py index 7d7dcd5..bb130e0 100644 --- a/serox/option.py +++ b/serox/option.py @@ -355,13 +355,13 @@ def __and__[U](self: Option[T], optb: Option[U], /) -> Option[U]: @overload def and_then[U](self: Null[T], f: Fn1[T, U], /) -> Null[U]: ... @overload - def and_then[U](self: Some[T], f: Fn1[T, U], /) -> Option[U]: ... - def and_then[U](self: Option[T], f: Callable[[T], Option[U]], /) -> Option[U]: + def and_then[U](self: Some[T], f: Fn1[T, U], /) -> U: ... + def and_then[U](self: Option[T], f: Fn1[T, U], /) -> U | Null[U]: """ Returns `Null` if the option is `Null` otherwise calls `f` with the wrapped value and returns the result. - Some languages call this operation flatmap. + Some languages call this operation 'flatmap'. Examples ======== diff --git a/serox/vec.py b/serox/vec.py index 4fb6dc2..5c3521d 100644 --- a/serox/vec.py +++ b/serox/vec.py @@ -31,7 +31,7 @@ from serox.conftest import TESTING -from serox.misc import Clone, SizedIndexable +from serox.misc import Clone, IndexType, SizedIndexable from serox.option import Null, Option, Some if TYPE_CHECKING: @@ -52,6 +52,10 @@ class Iter[Item, P: (True_, False_)](DoubleEndedIterator[Item, P]): end_or_len: int ptr: int + """ + Wrapper around a native Python :class:`list` to endow it with `Vec`-like functionality. + """ + @classmethod def new[Item2, Par2: (True_, False_)]( cls, data: SizedIndexable[Item2], /, par: Par2 = False @@ -80,6 +84,28 @@ def next_back(self) -> Option[Item]: return self._next(back=True) +@dataclass(repr=True, frozen=True, kw_only=True) +class SampledIndexable[Item](SizedIndexable[Item]): + data: SizedIndexable[Item] + indices: list[IndexType] + + @classmethod + def new[Item2]( + cls, + data: SizedIndexable[Item2], + indices: list[IndexType], + ) -> SampledIndexable[Item2]: + return SampledIndexable(data=data, indices=indices) + + @override + def __getitem__(self, index: IndexType, /) -> Item: + return self.data[self.indices[index]] + + @override + def __len__(self) -> int: + return len(self.indices) + + class Vec[T]( IntoIterator[T], IntoParIterator[T], @@ -92,7 +118,7 @@ class Vec[T]( Into[list[T]], ): """ - Wrapper around a native Python :class:`list` to endow it with `Vec`-mimetic functionality. + Wrapper around a native Python :class:`list` to endow it with `Vec`-like functionality. """ def __init__(self, *args: T) -> None: @@ -102,10 +128,20 @@ def __init__(self, *args: T) -> None: @override @classmethod def default(cls: type[Vec[T]]) -> Vec[T]: + """ + Returns a new, empty `Vec` as the default. + + :returns: A new, empty `Vec`. + """ return Vec[T]() @classmethod def new(cls) -> Vec[T]: + """ + Returns a new, empty `Vec`. + + :returns: A new, empty `Vec`. + """ return Vec[T].default() @override @@ -135,6 +171,11 @@ def par_iter(self) -> DoubleEndedIterator[T, True_]: return Iter.new(self, par=True) def __iter__(self) -> Generator[T, None, None]: + """ + Returns a generator over the elements of the `Vec`. + + :yield: Elements of the `Vec` in order. + """ yield from self.iter() @override @@ -207,26 +248,61 @@ def split_off(self, at: int, /) -> Vec[T]: @classmethod def full(cls, value: T, n: int) -> Vec[T]: + """ + Initializes a new `Vec` with `n` copies of `value`. + + :param value: The value to fill the `Vec` with. + :param n: The number of copies of `value` to fill the `Vec` with. + :returns: A new `Vec` with `n` copies of `value`. + """ return Vec[T](*(value for _ in range(n))) def push(self, item: T, /) -> None: + """ + Appends an item to the end of the `Vec`. + + :param item: The item to append. + """ self.inner.append(item) def clear(self) -> None: + """ + Removes all elements from the `Vec`. + """ self.inner.clear() @override def extend(self, items: Iterable[T], /) -> None: + """ + Extends the `Vec` with the elements from the given iterable. + + :param items: The iterable of items to extend the `Vec` with. + """ self.inner.extend(items) def append(self, other: Self, /): + """ + Appends the elements of another `Vec` to this `Vec`, then clears the other `Vec`. + + :param other: The `Vec` to append. + """ self.inner.extend(other.iter()) other.clear() def first(self) -> Option[T]: + """ + Returns the first element of the `Vec`, or `Null` if the `Vec` is empty. + + :returns: The first element of the `Vec`, or `Null` if the `Vec` is empty. + """ return Null() if self.is_empty() else Some(self[0]) def last(self) -> Option[T]: + """ + Returns the last element of the `Vec`, or `Null` if the `Vec` is empty. + + :returns: The last element of the `Vec`, or `Null` if the `Vec` is empty. + """ return Null() if self.is_empty() else Some(self[-1]) def sort_by( @@ -235,15 +311,31 @@ def sort_by( /, reverse: bool = False, ) -> None: + """ + Sorts the `Vec` in place using the given comparison function. + + :param compare: The comparison function to use for sorting. + :param reverse: If `True`, the `Vec` is sorted in reverse order. + """ self.inner.sort(key=compare, reverse=reverse) def sort[U: PartialOrd]( self: Vec[U], reverse: bool = False, ) -> None: + """ + Sorts the `Vec` in place. + + :param reverse: If `True`, the `Vec` is sorted in reverse order. + """ self.inner.sort(reverse=reverse) def pop(self) -> Option[T]: + """ + Pop the last element from the vector and return it. + :returns: `Some(x)`, where `x` is the last element of the vector if it is not empty, + otherwise `Null`. + """ if self.is_empty(): return Null() return Some(self.inner.pop()) @@ -255,7 +347,7 @@ def remove(self, index: int) -> T: :param index: The index of the element to remove. :returns: The removed element previously at index `index` of the vector. - :raises: :class:`IndexError` if `index` is out of bounds. + :raises IndexError: if `index` is out of bounds. """ if index >= self.len(): raise IndexError(f"removal index (is {index}) should be < len (is {self.len()})") @@ -274,13 +366,29 @@ def insert(self, index: int, element: T) -> None: @override @classmethod def from_iter[P: (True_, False_)](cls, s: Iterator[T, P], /) -> Vec[T]: + """ + Creates a new `Vec` from an iterator. + + :param s: The iterator to create the `Vec` from. + :returns: A new `Vec` containing the elements from the iterator. + """ return Vec(*s) @override def clone(self) -> Self: + """ + Creates a clone of the `Vec`. + + :returns: A clone of the `Vec`. + """ return super().clone() def retain(self, f: Fn1[T, bool], /) -> None: + """ + Retains only the elements specified by the predicate function. + + :param f: The predicate function to determine which elements to retain. + """ self.inner = list(filter(f, self.inner)) def choose(self, rng: Rng) -> Option[T]: @@ -312,9 +420,9 @@ def choose_multiple(self, rng: Rng, amount: int) -> Iter[T, False_]: """ # cap the sample size at the population size amount = min(amount, self.len()) - # TODO: Sample indices instead, passing them to a dedicated iterator to lazily sample - # elements from `inner`. - return Iter.new(rng.sample(self.inner, k=amount), par=False) + # sample without replacement + sampled_indices = rng.sample(range(self.len()), k=amount) + return Iter.new(SampledIndexable.new(self, sampled_indices), par=False) @qmark def choose_multiple_weighted( @@ -353,24 +461,63 @@ def call(x: T) -> float: return Ok(Iter.new(rng.choices(self.inner, weights=weights, k=amount), par=False)) def shuffle(self, rng: Rng) -> None: + """ + Shuffles the elements of the `Vec` in place using the given random number generator. + + :param rng: The random number generator to use for shuffling. + """ rng.shuffle(self.inner) def fill(self, value: T, /) -> None: + """ + Fills the `Vec` with the given value. + + :param value: The value to fill the `Vec` with. + """ self.inner = self.len() * [value] def fill_with(self, f: Fn0[T], /) -> None: + """ + Fills the `Vec` with values generated by the given function. + + :param f: The function to generate values to fill the `Vec` with. + """ self.inner = [f() for _ in range(self.len())] def join[U: str](self: Vec[U], separator: U, /) -> U: + """ + Joins the elements of the `Vec` into a string, separated by the given separator. + + :param separator: The separator to use between elements. + :returns: A string with the elements of the `Vec` joined by `separator`. + """ return separator.join(self.inner) def repeat(self, n: int, /) -> Vec[T]: + """ + Repeats the elements of the `Vec` `n` times. + + :param n: The number of times to repeat the elements. + :returns: A new `Vec` with the elements repeated `n` times. + """ return Vec(*(self.inner * n)) def flatten[U](self: Vec[Vec[U]]) -> Vec[U]: + """ + Flattens a `Vec` of `Vec`s into a single `Vec`. + + :returns: A new `Vec` with the elements of the inner `Vec`s. + """ return Vec(*(inner for outer in self for inner in outer)) def dedup(self) -> None: + """ + Removes consecutive duplicate elements from the `Vec`. + + This method retains only the first occurrence of each group of consecutive duplicate elements. + + :returns: None + """ # iterator to start from the second (first) element next_iter = self.iter() # offset the iterator by one. If there is no second element, return `Null`, otherwise @@ -399,22 +546,25 @@ def not_repeated(pair: tuple[T, T], /) -> bool: if TESTING: import math - def test_vec(): + def test_sort(): + vec = Vec[int](3, 2, 1) + vec.sort() + assert vec == Vec(1, 2, 3) + vec.sort(reverse=True) + assert vec == Vec(3, 2, 1) + vec.sort_by(lambda x: -x, reverse=True) + assert vec == Vec(1, 2, 3) + + def test_filter(): + vec = Vec[int](1, 2, 3, 6) + evens = vec.iter().filter(lambda x: x % 2 == 0).collect(Vec[int]) + assert evens == Vec(2, 6) + + def test_chain(): vec = Vec[int](1, 2, 3) - assert vec.len() == 3 - assert vec == Vec[float](1.0, 2, 3) vec2 = Vec[int](2, 3, 4) - _: Vec[int] = vec.iter().map(lambda x: x * 2).zip(vec2.iter()).collect(Vec) - res = vec.iter().chain(vec2.iter()).collect(Vec[int]) - - evens = vec.iter().filter(lambda x: bool(1 & ~x)).collect(Vec[int]) - assert evens == Vec(2) - - Vec(Vec[int].default()).sort_by(lambda x: x.len()) - res.sort() - - for item in res: - del item + res: Vec[int] = vec.iter().chain(vec2.iter()).collect(Vec) + assert res == Vec(1, 2, 3, 2, 3, 4) def test_take(): vec = Vec[float].full(math.pi, 3) @@ -436,13 +586,17 @@ def test_take_while(): def test_par_iter(): vec = Vec[float].full(3.14, n=3) - _ = vec.par_iter().take(2).collect(Vec[float]) + res = vec.par_iter().take(2).collect(Vec[float]) + assert len(res) == 2 def test_agg(): - vec = Vec[float].full(3.14, n=3) - _ = vec.iter().sum() - _ = vec.iter().product() - _ = vec.iter().max() + vec = Vec[float](1.0, 2.0, 3.0, -3.0) + sum_ = vec.iter().sum() + assert sum_ == 3.0 + prod = vec.iter().product() + assert prod == -18.0 + max_ = vec.iter().max() + assert max_ == 3.0 def test_chunking(): vec = Vec(*range(97))