mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00

Some checks are pending
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / benchmarks (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
896 lines
No EOL
52 KiB
JSON
Generated
896 lines
No EOL
52 KiB
JSON
Generated
{
|
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
"title": "Options",
|
|
"type": "object",
|
|
"properties": {
|
|
"environment": {
|
|
"description": "Configures the type checking environment.",
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/EnvironmentOptions"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"respect-ignore-files": {
|
|
"description": "Whether to automatically exclude files that are ignored by `.ignore`, `.gitignore`, `.git/info/exclude`, and global `gitignore` files. Enabled by default.",
|
|
"type": [
|
|
"boolean",
|
|
"null"
|
|
]
|
|
},
|
|
"rules": {
|
|
"description": "Configures the enabled rules and their severity.\n\nSee [the rules documentation](https://ty.dev/rules) for a list of all available rules.\n\nValid severities are:\n\n* `ignore`: Disable the rule. * `warn`: Enable the rule and create a warning diagnostic. * `error`: Enable the rule and create an error diagnostic. ty will exit with a non-zero code if any error diagnostics are emitted.",
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/Rules"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"src": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/SrcOptions"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"terminal": {
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/TerminalOptions"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"additionalProperties": false,
|
|
"definitions": {
|
|
"DiagnosticFormat": {
|
|
"description": "The diagnostic output format.",
|
|
"oneOf": [
|
|
{
|
|
"description": "The default full mode will print \"pretty\" diagnostics.\n\nThat is, color will be used when printing to a `tty`. Moreover, diagnostic messages may include additional context and annotations on the input to help understand the message.",
|
|
"type": "string",
|
|
"enum": [
|
|
"full"
|
|
]
|
|
},
|
|
{
|
|
"description": "Print diagnostics in a concise mode.\n\nThis will guarantee that each diagnostic is printed on a single line. Only the most important or primary aspects of the diagnostic are included. Contextual information is dropped.\n\nThis may use color when printing to a `tty`.",
|
|
"type": "string",
|
|
"enum": [
|
|
"concise"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
"EnvironmentOptions": {
|
|
"type": "object",
|
|
"properties": {
|
|
"extra-paths": {
|
|
"description": "List of user-provided paths that should take first priority in the module resolution. Examples in other type checkers are mypy's `MYPYPATH` environment variable, or pyright's `stubPath` configuration setting.",
|
|
"type": [
|
|
"array",
|
|
"null"
|
|
],
|
|
"items": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"python": {
|
|
"description": "Path to the Python installation from which ty resolves type information and third-party dependencies.\n\nty will search in the path's `site-packages` directories for type information and third-party imports.\n\nThis option is commonly used to specify the path to a virtual environment.",
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
},
|
|
"python-platform": {
|
|
"description": "Specifies the target platform that will be used to analyze the source code. If specified, ty will understand conditions based on comparisons with `sys.platform`, such as are commonly found in typeshed to reflect the differing contents of the standard library across platforms.\n\nIf no platform is specified, ty will use the current platform: - `win32` for Windows - `darwin` for macOS - `android` for Android - `ios` for iOS - `linux` for everything else",
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/PythonPlatform"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"python-version": {
|
|
"description": "Specifies the version of Python that will be used to analyze the source code. The version should be specified as a string in the format `M.m` where `M` is the major version and `m` is the minor (e.g. `\"3.0\"` or `\"3.6\"`). If a version is provided, ty will generate errors if the source code makes use of language features that are not supported in that version. It will also understand conditionals based on comparisons with `sys.version_info`, such as are commonly found in typeshed to reflect the differing contents of the standard library across Python versions.",
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/PythonVersion"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
},
|
|
"typeshed": {
|
|
"description": "Optional path to a \"typeshed\" directory on disk for us to use for standard-library types. If this is not provided, we will fallback to our vendored typeshed stubs for the stdlib, bundled as a zip file in the binary",
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
}
|
|
},
|
|
"additionalProperties": false
|
|
},
|
|
"Level": {
|
|
"oneOf": [
|
|
{
|
|
"title": "Ignore",
|
|
"description": "The lint is disabled and should not run.",
|
|
"type": "string",
|
|
"enum": [
|
|
"ignore"
|
|
]
|
|
},
|
|
{
|
|
"title": "Warn",
|
|
"description": "The lint is enabled and diagnostic should have a warning severity.",
|
|
"type": "string",
|
|
"enum": [
|
|
"warn"
|
|
]
|
|
},
|
|
{
|
|
"title": "Error",
|
|
"description": "The lint is enabled and diagnostics have an error severity.",
|
|
"type": "string",
|
|
"enum": [
|
|
"error"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
"PythonPlatform": {
|
|
"anyOf": [
|
|
{
|
|
"type": "string"
|
|
},
|
|
{
|
|
"description": "Do not make any assumptions about the target platform.",
|
|
"const": "all"
|
|
},
|
|
{
|
|
"description": "Darwin",
|
|
"const": "darwin"
|
|
},
|
|
{
|
|
"description": "Linux",
|
|
"const": "linux"
|
|
},
|
|
{
|
|
"description": "Windows",
|
|
"const": "win32"
|
|
}
|
|
]
|
|
},
|
|
"PythonVersion": {
|
|
"anyOf": [
|
|
{
|
|
"type": "string",
|
|
"pattern": "^\\d+\\.\\d+$"
|
|
},
|
|
{
|
|
"description": "Python 3.7",
|
|
"const": "3.7"
|
|
},
|
|
{
|
|
"description": "Python 3.8",
|
|
"const": "3.8"
|
|
},
|
|
{
|
|
"description": "Python 3.9",
|
|
"const": "3.9"
|
|
},
|
|
{
|
|
"description": "Python 3.10",
|
|
"const": "3.10"
|
|
},
|
|
{
|
|
"description": "Python 3.11",
|
|
"const": "3.11"
|
|
},
|
|
{
|
|
"description": "Python 3.12",
|
|
"const": "3.12"
|
|
},
|
|
{
|
|
"description": "Python 3.13",
|
|
"const": "3.13"
|
|
},
|
|
{
|
|
"description": "Python 3.14",
|
|
"const": "3.14"
|
|
}
|
|
]
|
|
},
|
|
"Rules": {
|
|
"type": "object",
|
|
"properties": {
|
|
"byte-string-type-annotation": {
|
|
"title": "detects byte strings in type annotation positions",
|
|
"description": "## What it does\nChecks for byte-strings in type annotation positions.\n\n## Why is this bad?\nStatic analysis tools like ty can't analyse type annotations that use byte-string notation.\n\n## Examples\n```python\ndef test(): -> b\"int\":\n ...\n```\n\nUse instead:\n```python\ndef test(): -> \"int\":\n ...\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"call-non-callable": {
|
|
"title": "detects calls to non-callable objects",
|
|
"description": "## What it does\nChecks for calls to non-callable objects.\n\n## Why is this bad?\nCalling a non-callable object will raise a `TypeError` at runtime.\n\n## Examples\n```python\n4() # TypeError: 'int' object is not callable\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"call-possibly-unbound-method": {
|
|
"title": "detects calls to possibly unbound methods",
|
|
"description": "## What it does\nChecks for calls to possibly unbound methods.\n\n## Why is this bad?\nCalling an unbound method will raise an `AttributeError` at runtime.",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"conflicting-argument-forms": {
|
|
"title": "detects when an argument is used as both a value and a type form in a call",
|
|
"description": "## What it does\nChecks whether an argument is used as both a value and a type form in a call.\n\n## Why is this bad?\nSuch calls have confusing semantics and often indicate a logic error.\n\n## Examples\n```python\nfrom typing import reveal_type\nfrom ty_extensions import is_fully_static\n\nif flag:\n f = repr # Expects a value\nelse:\n f = is_fully_static # Expects a type form\n\nf(int) # error\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"conflicting-declarations": {
|
|
"title": "detects conflicting declarations",
|
|
"description": "## What it does\nChecks whether a variable has been declared as two conflicting types.\n\n## Why is this bad\nA variable with two conflicting declarations likely indicates a mistake.\nMoreover, it could lead to incorrect or ill-defined type inference for\nother code that relies on these variables.\n\n## Examples\n```python\nif b:\n a: int\nelse:\n a: str\n\na = 1\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"conflicting-metaclass": {
|
|
"title": "detects conflicting metaclasses",
|
|
"description": "## What it does\nChecks for class definitions where the metaclass of the class\nbeing created would not be a subclass of the metaclasses of\nall the class's bases.\n\n## Why is it bad?\nSuch a class definition raises a `TypeError` at runtime.\n\n## Examples\n```python\nclass M1(type): ...\nclass M2(type): ...\nclass A(metaclass=M1): ...\nclass B(metaclass=M2): ...\n\n# TypeError: metaclass conflict\nclass C(A, B): ...\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"cyclic-class-definition": {
|
|
"title": "detects cyclic class definitions",
|
|
"description": "## What it does\nChecks for class definitions in stub files that inherit\n(directly or indirectly) from themselves.\n\n## Why is it bad?\nAlthough forward references are natively supported in stub files,\ninheritance cycles are still disallowed, as it is impossible to\nresolve a consistent [method resolution order] for a class that\ninherits from itself.\n\n## Examples\n```python\n# foo.pyi\nclass A(B): ...\nclass B(A): ...\n```\n\n[method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"division-by-zero": {
|
|
"title": "detects division by zero",
|
|
"description": "## What it does\nIt detects division by zero.\n\n## Why is this bad?\nDividing by zero raises a `ZeroDivisionError` at runtime.\n\n## Examples\n```python\n5 / 0\n```",
|
|
"default": "ignore",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"duplicate-base": {
|
|
"title": "detects class definitions with duplicate bases",
|
|
"description": "## What it does\nChecks for class definitions with duplicate bases.\n\n## Why is this bad?\nClass definitions with duplicate bases raise `TypeError` at runtime.\n\n## Examples\n```python\nclass A: ...\n\n# TypeError: duplicate base class\nclass B(A, A): ...\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"escape-character-in-forward-annotation": {
|
|
"title": "detects forward type annotations with escape characters",
|
|
"description": "TODO #14889",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"fstring-type-annotation": {
|
|
"title": "detects F-strings in type annotation positions",
|
|
"description": "## What it does\nChecks for f-strings in type annotation positions.\n\n## Why is this bad?\nStatic analysis tools like ty can't analyse type annotations that use f-string notation.\n\n## Examples\n```python\ndef test(): -> f\"int\":\n ...\n```\n\nUse instead:\n```python\ndef test(): -> \"int\":\n ...\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"implicit-concatenated-string-type-annotation": {
|
|
"title": "detects implicit concatenated strings in type annotations",
|
|
"description": "## What it does\nChecks for implicit concatenated strings in type annotation positions.\n\n## Why is this bad?\nStatic analysis tools like ty can't analyse type annotations that use implicit concatenated strings.\n\n## Examples\n```python\ndef test(): -> \"Literal[\" \"5\" \"]\":\n ...\n```\n\nUse instead:\n```python\ndef test(): -> \"Literal[5]\":\n ...\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"incompatible-slots": {
|
|
"title": "detects class definitions whose MRO has conflicting `__slots__`",
|
|
"description": "## What it does\nChecks for classes whose bases define incompatible `__slots__`.\n\n## Why is this bad?\nInheriting from bases with incompatible `__slots__`s\nwill lead to a `TypeError` at runtime.\n\nClasses with no or empty `__slots__` are always compatible:\n\n```python\nclass A: ...\nclass B:\n __slots__ = ()\nclass C:\n __slots__ = (\"a\", \"b\")\n\n# fine\nclass D(A, B, C): ...\n```\n\nMultiple inheritance from more than one different class\ndefining non-empty `__slots__` is not allowed:\n\n```python\nclass A:\n __slots__ = (\"a\", \"b\")\n\nclass B:\n __slots__ = (\"a\", \"b\") # Even if the values are the same\n\n# TypeError: multiple bases have instance lay-out conflict\nclass C(A, B): ...\n```\n\n## Known problems\nDynamic (not tuple or string literal) `__slots__` are not checked.\nAdditionally, classes inheriting from built-in classes with implicit layouts\nlike `str` or `int` are also not checked.\n\n```pycon\n>>> hasattr(int, \"__slots__\")\nFalse\n>>> hasattr(str, \"__slots__\")\nFalse\n>>> class A(int, str): ...\nTraceback (most recent call last):\n File \"<python-input-0>\", line 1, in <module>\n class A(int, str): ...\nTypeError: multiple bases have instance lay-out conflict\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"inconsistent-mro": {
|
|
"title": "detects class definitions with an inconsistent MRO",
|
|
"description": "## What it does\nChecks for classes with an inconsistent [method resolution order] (MRO).\n\n## Why is this bad?\nClasses with an inconsistent MRO will raise a `TypeError` at runtime.\n\n## Examples\n```python\nclass A: ...\nclass B(A): ...\n\n# TypeError: Cannot create a consistent method resolution order\nclass C(A, B): ...\n```\n\n[method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"index-out-of-bounds": {
|
|
"title": "detects index out of bounds errors",
|
|
"description": "## What it does\nChecks for attempts to use an out of bounds index to get an item from\na container.\n\n## Why is this bad?\nUsing an out of bounds index will raise an `IndexError` at runtime.\n\n## Examples\n```python\nt = (0, 1, 2)\nt[3] # IndexError: tuple index out of range\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-argument-type": {
|
|
"title": "detects call arguments whose type is not assignable to the corresponding typed parameter",
|
|
"description": "## What it does\nDetects call arguments whose type is not assignable to the corresponding typed parameter.\n\n## Why is this bad?\nPassing an argument of a type the function (or callable object) does not accept violates\nthe expectations of the function author and may cause unexpected runtime errors within the\nbody of the function.\n\n## Examples\n```python\ndef func(x: int): ...\nfunc(\"foo\") # error: [invalid-argument-type]\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-assignment": {
|
|
"title": "detects invalid assignments",
|
|
"description": "## What it does\nChecks for assignments where the type of the value\nis not [assignable to] the type of the assignee.\n\n## Why is this bad?\nSuch assignments break the rules of the type system and\nweaken a type checker's ability to accurately reason about your code.\n\n## Examples\n```python\na: int = ''\n```\n\n[assignable to]: https://typing.python.org/en/latest/spec/glossary.html#term-assignable",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-attribute-access": {
|
|
"title": "Invalid attribute access",
|
|
"description": "## What it does\nChecks for assignments to class variables from instances\nand assignments to instance variables from its class.\n\n## Why is this bad?\nIncorrect assignments break the rules of the type system and\nweaken a type checker's ability to accurately reason about your code.\n\n## Examples\n```python\nclass C:\n class_var: ClassVar[int] = 1\n instance_var: int\n\nC.class_var = 3 # okay\nC().class_var = 3 # error: Cannot assign to class variable\n\nC().instance_var = 3 # okay\nC.instance_var = 3 # error: Cannot assign to instance variable\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-base": {
|
|
"title": "detects class bases that will cause the class definition to raise an exception at runtime",
|
|
"description": "## What it does\nChecks for class definitions that have bases which are not instances of `type`.\n\n## Why is this bad?\nClass definitions with bases like this will lead to `TypeError` being raised at runtime.\n\n## Examples\n```python\nclass A(42): ... # error: [invalid-base]\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-context-manager": {
|
|
"title": "detects expressions used in with statements that don't implement the context manager protocol",
|
|
"description": "## What it does\nChecks for expressions used in `with` statements\nthat do not implement the context manager protocol.\n\n## Why is this bad?\nSuch a statement will raise `TypeError` at runtime.\n\n## Examples\n```python\n# TypeError: 'int' object does not support the context manager protocol\nwith 1:\n print(2)\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-declaration": {
|
|
"title": "detects invalid declarations",
|
|
"description": "## What it does\nChecks for declarations where the inferred type of an existing symbol\nis not [assignable to] its post-hoc declared type.\n\n## Why is this bad?\nSuch declarations break the rules of the type system and\nweaken a type checker's ability to accurately reason about your code.\n\n## Examples\n```python\na = 1\na: str\n```\n\n[assignable to]: https://typing.python.org/en/latest/spec/glossary.html#term-assignable",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-exception-caught": {
|
|
"title": "detects exception handlers that catch classes that do not inherit from `BaseException`",
|
|
"description": "## What it does\nChecks for exception handlers that catch non-exception classes.\n\n## Why is this bad?\nCatching classes that do not inherit from `BaseException` will raise a TypeError at runtime.\n\n## Example\n```python\ntry:\n 1 / 0\nexcept 1:\n ...\n```\n\nUse instead:\n```python\ntry:\n 1 / 0\nexcept ZeroDivisionError:\n ...\n```\n\n## References\n- [Python documentation: except clause](https://docs.python.org/3/reference/compound_stmts.html#except-clause)\n- [Python documentation: Built-in Exceptions](https://docs.python.org/3/library/exceptions.html#built-in-exceptions)\n\n## Ruff rule\n This rule corresponds to Ruff's [`except-with-non-exception-classes` (`B030`)](https://docs.astral.sh/ruff/rules/except-with-non-exception-classes)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-generic-class": {
|
|
"title": "detects invalid generic classes",
|
|
"description": "## What it does\nChecks for the creation of invalid generic classes\n\n## Why is this bad?\nThere are several requirements that you must follow when defining a generic class.\n\n## Examples\n```python\nfrom typing import Generic, TypeVar\n\nT = TypeVar(\"T\") # okay\n\n# error: class uses both PEP-695 syntax and legacy syntax\nclass C[U](Generic[T]): ...\n```\n\n## References\n- [Typing spec: Generics](https://typing.python.org/en/latest/spec/generics.html#introduction)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-ignore-comment": {
|
|
"title": "detects ignore comments that use invalid syntax",
|
|
"description": "## What it does\nChecks for `type: ignore` and `ty: ignore` comments that are syntactically incorrect.\n\n## Why is this bad?\nA syntactically incorrect ignore comment is probably a mistake and is useless.\n\n## Examples\n```py\na = 20 / 0 # type: ignoree\n```\n\nUse instead:\n\n```py\na = 20 / 0 # type: ignore\n```",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-legacy-type-variable": {
|
|
"title": "detects invalid legacy type variables",
|
|
"description": "## What it does\nChecks for the creation of invalid legacy `TypeVar`s\n\n## Why is this bad?\nThere are several requirements that you must follow when creating a legacy `TypeVar`.\n\n## Examples\n```python\nfrom typing import TypeVar\n\nT = TypeVar(\"T\") # okay\nQ = TypeVar(\"S\") # error: TypeVar name must match the variable it's assigned to\nT = TypeVar(\"T\") # error: TypeVars should not be redefined\n\n# error: TypeVar must be immediately assigned to a variable\ndef f(t: TypeVar(\"U\")): ...\n```\n\n## References\n- [Typing spec: Generics](https://typing.python.org/en/latest/spec/generics.html#introduction)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-metaclass": {
|
|
"title": "detects invalid `metaclass=` arguments",
|
|
"description": "## What it does\nChecks for arguments to `metaclass=` that are invalid.\n\n## Why is this bad?\nPython allows arbitrary expressions to be used as the argument to `metaclass=`.\nThese expressions, however, need to be callable and accept the same arguments\nas `type.__new__`.\n\n## Example\n\n```python\ndef f(): ...\n\n# TypeError: f() takes 0 positional arguments but 3 were given\nclass B(metaclass=f): ...\n```\n\n## References\n- [Python documentation: Metaclasses](https://docs.python.org/3/reference/datamodel.html#metaclasses)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-overload": {
|
|
"title": "detects invalid `@overload` usages",
|
|
"description": "## What it does\nChecks for various invalid `@overload` usages.\n\n## Why is this bad?\nThe `@overload` decorator is used to define functions and methods that accepts different\ncombinations of arguments and return different types based on the arguments passed. This is\nmainly beneficial for type checkers. But, if the `@overload` usage is invalid, the type\nchecker may not be able to provide correct type information.\n\n## Example\n\nDefining only one overload:\n\n```py\nfrom typing import overload\n\n@overload\ndef foo(x: int) -> int: ...\ndef foo(x: int | None) -> int | None:\n return x\n```\n\nOr, not providing an implementation for the overloaded definition:\n\n```py\nfrom typing import overload\n\n@overload\ndef foo() -> None: ...\n@overload\ndef foo(x: int) -> int: ...\n```\n\n## References\n- [Python documentation: `@overload`](https://docs.python.org/3/library/typing.html#typing.overload)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-parameter-default": {
|
|
"title": "detects default values that can't be assigned to the parameter's annotated type",
|
|
"description": "## What it does\nChecks for default values that can't be\nassigned to the parameter's annotated type.\n\n## Why is this bad?\nThis breaks the rules of the type system and\nweakens a type checker's ability to accurately reason about your code.\n\n## Examples\n```python\ndef f(a: int = ''): ...\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-protocol": {
|
|
"title": "detects invalid protocol class definitions",
|
|
"description": "## What it does\nChecks for invalidly defined protocol classes.\n\n## Why is this bad?\nAn invalidly defined protocol class may lead to the type checker inferring\nunexpected things. It may also lead to `TypeError`s at runtime.\n\n## Examples\nA `Protocol` class cannot inherit from a non-`Protocol` class;\nthis raises a `TypeError` at runtime:\n\n```pycon\n>>> from typing import Protocol\n>>> class Foo(int, Protocol): ...\n...\nTraceback (most recent call last):\n File \"<python-input-1>\", line 1, in <module>\n class Foo(int, Protocol): ...\nTypeError: Protocols can only inherit from other protocols, got <class 'int'>\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-raise": {
|
|
"title": "detects `raise` statements that raise invalid exceptions or use invalid causes",
|
|
"description": "Checks for `raise` statements that raise non-exceptions or use invalid\ncauses for their raised exceptions.\n\n## Why is this bad?\nOnly subclasses or instances of `BaseException` can be raised.\nFor an exception's cause, the same rules apply, except that `None` is also\npermitted. Violating these rules results in a `TypeError` at runtime.\n\n## Examples\n```python\ndef f():\n try:\n something()\n except NameError:\n raise \"oops!\" from f\n\ndef g():\n raise NotImplemented from 42\n```\n\nUse instead:\n```python\ndef f():\n try:\n something()\n except NameError as e:\n raise RuntimeError(\"oops!\") from e\n\ndef g():\n raise NotImplementedError from None\n```\n\n## References\n- [Python documentation: The `raise` statement](https://docs.python.org/3/reference/simple_stmts.html#raise)\n- [Python documentation: Built-in Exceptions](https://docs.python.org/3/library/exceptions.html#built-in-exceptions)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-return-type": {
|
|
"title": "detects returned values that can't be assigned to the function's annotated return type",
|
|
"description": "## What it does\nDetects returned values that can't be assigned to the function's annotated return type.\n\n## Why is this bad?\nReturning an object of a type incompatible with the annotated return type may cause confusion to the user calling the function.\n\n## Examples\n```python\ndef func() -> int:\n return \"a\" # error: [invalid-return-type]\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-super-argument": {
|
|
"title": "detects invalid arguments for `super()`",
|
|
"description": "## What it does\nDetects `super()` calls where:\n- the first argument is not a valid class literal, or\n- the second argument is not an instance or subclass of the first argument.\n\n## Why is this bad?\n`super(type, obj)` expects:\n- the first argument to be a class,\n- and the second argument to satisfy one of the following:\n - `isinstance(obj, type)` is `True`\n - `issubclass(obj, type)` is `True`\n\nViolating this relationship will raise a `TypeError` at runtime.\n\n## Examples\n```python\nclass A:\n ...\nclass B(A):\n ...\n\nsuper(A, B()) # it's okay! `A` satisfies `isinstance(B(), A)`\n\nsuper(A(), B()) # error: `A()` is not a class\n\nsuper(B, A()) # error: `A()` does not satisfy `isinstance(A(), B)`\nsuper(B, A) # error: `A` does not satisfy `issubclass(A, B)`\n```\n\n## References\n- [Python documentation: super()](https://docs.python.org/3/library/functions.html#super)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-syntax-in-forward-annotation": {
|
|
"title": "detects invalid syntax in forward annotations",
|
|
"description": "TODO #14889",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-type-alias-type": {
|
|
"title": "detects invalid TypeAliasType definitions",
|
|
"description": "## What it does\nChecks for the creation of invalid `TypeAliasType`s\n\n## Why is this bad?\nThere are several requirements that you must follow when creating a `TypeAliasType`.\n\n## Examples\n```python\nfrom typing import TypeAliasType\n\nIntOrStr = TypeAliasType(\"IntOrStr\", int | str) # okay\nNewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name must be a string literal\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-type-checking-constant": {
|
|
"title": "detects invalid `TYPE_CHECKING` constant assignments",
|
|
"description": "## What it does\nChecks for a value other than `False` assigned to the `TYPE_CHECKING` variable, or an\nannotation not assignable from `bool`.\n\n## Why is this bad?\nThe name `TYPE_CHECKING` is reserved for a flag that can be used to provide conditional\ncode seen only by the type checker, and not at runtime. Normally this flag is imported from\n`typing` or `typing_extensions`, but it can also be defined locally. If defined locally, it\nmust be assigned the value `False` at runtime; the type checker will consider its value to\nbe `True`. If annotated, it must be annotated as a type that can accept `bool` values.\n\n## Examples\n```python\nTYPE_CHECKING: str\nTYPE_CHECKING = ''\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-type-form": {
|
|
"title": "detects invalid type forms",
|
|
"description": "## What it does\nChecks for expressions that are used as [type expressions]\nbut cannot validly be interpreted as such.\n\n## Why is this bad?\nSuch expressions cannot be understood by ty.\nIn some cases, they might raise errors at runtime.\n\n## Examples\n```python\nfrom typing import Annotated\n\na: type[1] # `1` is not a type\nb: Annotated[int] # `Annotated` expects at least two arguments\n```\n[type expressions]: https://typing.python.org/en/latest/spec/annotations.html#type-and-annotation-expressions",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"invalid-type-variable-constraints": {
|
|
"title": "detects invalid type variable constraints",
|
|
"description": "## What it does\nChecks for constrained [type variables] with only one constraint.\n\n## Why is this bad?\nA constrained type variable must have at least two constraints.\n\n## Examples\n```python\nfrom typing import TypeVar\n\nT = TypeVar('T', str) # invalid constrained TypeVar\n```\n\nUse instead:\n```python\nT = TypeVar('T', str, int) # valid constrained TypeVar\n# or\nT = TypeVar('T', bound=str) # valid bound TypeVar\n```\n\n[type variables]: https://docs.python.org/3/library/typing.html#typing.TypeVar",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"missing-argument": {
|
|
"title": "detects missing required arguments in a call",
|
|
"description": "## What it does\nChecks for missing required arguments in a call.\n\n## Why is this bad?\nFailing to provide a required argument will raise a `TypeError` at runtime.\n\n## Examples\n```python\ndef func(x: int): ...\nfunc() # TypeError: func() missing 1 required positional argument: 'x'\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"no-matching-overload": {
|
|
"title": "detects calls that do not match any overload",
|
|
"description": "## What it does\nChecks for calls to an overloaded function that do not match any of the overloads.\n\n## Why is this bad?\nFailing to provide the correct arguments to one of the overloads will raise a `TypeError`\nat runtime.\n\n## Examples\n```python\n@overload\ndef func(x: int): ...\n@overload\ndef func(x: bool): ...\nfunc(\"string\") # error: [no-matching-overload]\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"non-subscriptable": {
|
|
"title": "detects subscripting objects that do not support subscripting",
|
|
"description": "## What it does\nChecks for subscripting objects that do not support subscripting.\n\n## Why is this bad?\nSubscripting an object that does not support it will raise a `TypeError` at runtime.\n\n## Examples\n```python\n4[1] # TypeError: 'int' object is not subscriptable\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"not-iterable": {
|
|
"title": "detects iteration over an object that is not iterable",
|
|
"description": "## What it does\nChecks for objects that are not iterable but are used in a context that requires them to be.\n\n## Why is this bad?\nIterating over an object that is not iterable will raise a `TypeError` at runtime.\n\n## Examples\n\n```python\nfor i in 34: # TypeError: 'int' object is not iterable\n pass\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"parameter-already-assigned": {
|
|
"title": "detects multiple arguments for the same parameter",
|
|
"description": "## What it does\nChecks for calls which provide more than one argument for a single parameter.\n\n## Why is this bad?\nProviding multiple values for a single parameter will raise a `TypeError` at runtime.\n\n## Examples\n\n```python\ndef f(x: int) -> int: ...\n\nf(1, x=2) # Error raised here\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"possibly-unbound-attribute": {
|
|
"title": "detects references to possibly unbound attributes",
|
|
"description": "## What it does\nChecks for possibly unbound attributes.\n\n## Why is this bad?\nAttempting to access an unbound attribute will raise an `AttributeError` at runtime.\n\n## Examples\n```python\nclass A:\n if b:\n c = 0\n\nA.c # AttributeError: type object 'A' has no attribute 'c'\n```",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"possibly-unbound-import": {
|
|
"title": "detects possibly unbound imports",
|
|
"description": "## What it does\nChecks for imports of symbols that may be unbound.\n\n## Why is this bad?\nImporting an unbound module or name will raise a `ModuleNotFoundError`\nor `ImportError` at runtime.\n\n## Examples\n```python\n# module.py\nimport datetime\n\nif datetime.date.today().weekday() != 6:\n a = 1\n\n# main.py\nfrom module import a # ImportError: cannot import name 'a' from 'module'\n```",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"possibly-unresolved-reference": {
|
|
"title": "detects references to possibly undefined names",
|
|
"description": "## What it does\nChecks for references to names that are possibly not defined.\n\n## Why is this bad?\nUsing an undefined variable will raise a `NameError` at runtime.\n\n## Example\n\n```python\nfor i in range(0):\n x = i\n\nprint(x) # NameError: name 'x' is not defined\n```",
|
|
"default": "ignore",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"raw-string-type-annotation": {
|
|
"title": "detects raw strings in type annotation positions",
|
|
"description": "## What it does\nChecks for raw-strings in type annotation positions.\n\n## Why is this bad?\nStatic analysis tools like ty can't analyse type annotations that use raw-string notation.\n\n## Examples\n```python\ndef test(): -> r\"int\":\n ...\n```\n\nUse instead:\n```python\ndef test(): -> \"int\":\n ...\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"redundant-cast": {
|
|
"title": "detects redundant `cast` calls",
|
|
"description": "## What it does\nDetects redundant `cast` calls where the value already has the target type.\n\n## Why is this bad?\nThese casts have no effect and can be removed.\n\n## Example\n```python\ndef f() -> int:\n return 10\n\ncast(int, f()) # Redundant\n```",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"static-assert-error": {
|
|
"title": "Failed static assertion",
|
|
"description": "## What it does\nMakes sure that the argument of `static_assert` is statically known to be true.\n\n## Why is this bad?\nA `static_assert` call represents an explicit request from the user\nfor the type checker to emit an error if the argument cannot be verified\nto evaluate to `True` in a boolean context.\n\n## Examples\n```python\nfrom ty_extensions import static_assert\n\nstatic_assert(1 + 1 == 3) # error: evaluates to `False`\n\nstatic_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known truthiness\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"subclass-of-final-class": {
|
|
"title": "detects subclasses of final classes",
|
|
"description": "## What it does\nChecks for classes that subclass final classes.\n\n## Why is this bad?\nDecorating a class with `@final` declares to the type checker that it should not be subclassed.\n\n## Example\n\n```python\nfrom typing import final\n\n@final\nclass A: ...\nclass B(A): ... # Error raised here\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"too-many-positional-arguments": {
|
|
"title": "detects calls passing too many positional arguments",
|
|
"description": "## What it does\nChecks for calls that pass more positional arguments than the callable can accept.\n\n## Why is this bad?\nPassing too many positional arguments will raise `TypeError` at runtime.\n\n## Example\n\n```python\ndef f(): ...\n\nf(\"foo\") # Error raised here\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"type-assertion-failure": {
|
|
"title": "detects failed type assertions",
|
|
"description": "## What it does\nChecks for `assert_type()` and `assert_never()` calls where the actual type\nis not the same as the asserted type.\n\n## Why is this bad?\n`assert_type()` allows confirming the inferred type of a certain value.\n\n## Example\n\n```python\ndef _(x: int):\n assert_type(x, int) # fine\n assert_type(x, str) # error: Actual type does not match asserted type\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unavailable-implicit-super-arguments": {
|
|
"title": "detects invalid `super()` calls where implicit arguments are unavailable.",
|
|
"description": "## What it does\nDetects invalid `super()` calls where implicit arguments like the enclosing class or first method argument are unavailable.\n\n## Why is this bad?\nWhen `super()` is used without arguments, Python tries to find two things:\nthe nearest enclosing class and the first argument of the immediately enclosing function (typically self or cls).\nIf either of these is missing, the call will fail at runtime with a `RuntimeError`.\n\n## Examples\n```python\nsuper() # error: no enclosing class or function found\n\ndef func():\n super() # error: no enclosing class or first argument exists\n\nclass A:\n f = super() # error: no enclosing function to provide the first argument\n\n def method(self):\n def nested():\n super() # error: first argument does not exist in this nested function\n\n lambda: super() # error: first argument does not exist in this lambda\n\n (super() for _ in range(10)) # error: argument is not available in generator expression\n\n super() # okay! both enclosing class and first argument are available\n```\n\n## References\n- [Python documentation: super()](https://docs.python.org/3/library/functions.html#super)",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"undefined-reveal": {
|
|
"title": "detects usages of `reveal_type` without importing it",
|
|
"description": "## What it does\nChecks for calls to `reveal_type` without importing it.\n\n## Why is this bad?\nUsing `reveal_type` without importing it will raise a `NameError` at runtime.\n\n## Examples\n```python\nreveal_type(1) # NameError: name 'reveal_type' is not defined\n```",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unknown-argument": {
|
|
"title": "detects unknown keyword arguments in calls",
|
|
"description": "## What it does\nChecks for keyword arguments in calls that don't match any parameter of the callable.\n\n## Why is this bad?\nProviding an unknown keyword argument will raise `TypeError` at runtime.\n\n## Example\n\n```python\ndef f(x: int) -> int: ...\n\nf(x=1, y=2) # Error raised here\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unknown-rule": {
|
|
"title": "detects `ty: ignore` comments that reference unknown rules",
|
|
"description": "## What it does\nChecks for `ty: ignore[code]` where `code` isn't a known lint rule.\n\n## Why is this bad?\nA `ty: ignore[code]` directive with a `code` that doesn't match\nany known rule will not suppress any type errors, and is probably a mistake.\n\n## Examples\n```py\na = 20 / 0 # ty: ignore[division-by-zer]\n```\n\nUse instead:\n\n```py\na = 20 / 0 # ty: ignore[division-by-zero]\n```",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unresolved-attribute": {
|
|
"title": "detects references to unresolved attributes",
|
|
"description": "## What it does\nChecks for unresolved attributes.\n\n## Why is this bad?\nAccessing an unbound attribute will raise an `AttributeError` at runtime.\nAn unresolved attribute is not guaranteed to exist from the type alone,\nso this could also indicate that the object is not of the type that the user expects.\n\n## Examples\n```python\nclass A: ...\n\nA().foo # AttributeError: 'A' object has no attribute 'foo'\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unresolved-import": {
|
|
"title": "detects unresolved imports",
|
|
"description": "## What it does\nChecks for import statements for which the module cannot be resolved.\n\n## Why is this bad?\nImporting a module that cannot be resolved will raise a `ModuleNotFoundError`\nat runtime.\n\n## Examples\n```python\nimport foo # ModuleNotFoundError: No module named 'foo'\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unresolved-reference": {
|
|
"title": "detects references to names that are not defined",
|
|
"description": "## What it does\nChecks for references to names that are not defined.\n\n## Why is this bad?\nUsing an undefined variable will raise a `NameError` at runtime.\n\n## Example\n\n```python\nprint(x) # NameError: name 'x' is not defined\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unsupported-base": {
|
|
"title": "detects class bases that are unsupported as ty could not feasibly calculate the class's MRO",
|
|
"description": "## What it does\nChecks for class definitions that have bases which are unsupported by ty.\n\n## Why is this bad?\nIf a class has a base that is an instance of a complex type such as a union type,\nty will not be able to resolve the [method resolution order] (MRO) for the class.\nThis will lead to an inferior understanding of your codebase and unpredictable\ntype-checking behavior.\n\n## Examples\n```python\nimport datetime\n\nclass A: ...\nclass B: ...\n\nif datetime.date.today().weekday() != 6:\n C = A\nelse:\n C = B\n\nclass D(C): ... # error: [unsupported-base]\n```\n\n[method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order",
|
|
"default": "warn",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unsupported-bool-conversion": {
|
|
"title": "detects boolean conversion where the object incorrectly implements `__bool__`",
|
|
"description": "## What it does\nChecks for bool conversions where the object doesn't correctly implement `__bool__`.\n\n## Why is this bad?\nIf an exception is raised when you attempt to evaluate the truthiness of an object,\nusing the object in a boolean context will fail at runtime.\n\n## Examples\n\n```python\nclass NotBoolable:\n __bool__ = None\n\nb1 = NotBoolable()\nb2 = NotBoolable()\n\nif b1: # exception raised here\n pass\n\nb1 and b2 # exception raised here\nnot b1 # exception raised here\nb1 < b2 < b1 # exception raised here\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unsupported-operator": {
|
|
"title": "detects binary, unary, or comparison expressions where the operands don't support the operator",
|
|
"description": "## What it does\nChecks for binary expressions, comparisons, and unary expressions where\nthe operands don't support the operator.\n\n## Why is this bad?\nAttempting to use an unsupported operator will raise a `TypeError` at\nruntime.\n\n## Examples\n```python\nclass A: ...\n\nA() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A'\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"unused-ignore-comment": {
|
|
"title": "detects unused `type: ignore` comments",
|
|
"description": "## What it does\nChecks for `type: ignore` or `ty: ignore` directives that are no longer applicable.\n\n## Why is this bad?\nA `type: ignore` directive that no longer matches any diagnostic violations is likely\nincluded by mistake, and should be removed to avoid confusion.\n\n## Examples\n```py\na = 20 / 2 # ty: ignore[division-by-zero]\n```\n\nUse instead:\n\n```py\na = 20 / 2\n```",
|
|
"default": "ignore",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
},
|
|
"zero-stepsize-in-slice": {
|
|
"title": "detects a slice step size of zero",
|
|
"description": "## What it does\nChecks for step size 0 in slices.\n\n## Why is this bad?\nA slice with a step size of zero will raise a `ValueError` at runtime.\n\n## Examples\n```python\nl = list(range(10))\nl[1:10:0] # ValueError: slice step cannot be zero\n```",
|
|
"default": "error",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"additionalProperties": {
|
|
"$ref": "#/definitions/Level"
|
|
}
|
|
},
|
|
"SrcOptions": {
|
|
"type": "object",
|
|
"properties": {
|
|
"root": {
|
|
"description": "The root of the project, used for finding first-party modules.\n\nIf left unspecified, ty will try to detect common project layouts and initialize `src.root` accordingly:\n\n* if a `./src` directory exists, include `.` and `./src` in the first party search path (src layout or flat) * if a `./<project-name>/<project-name>` directory exists, include `.` and `./<project-name>` in the first party search path * otherwise, default to `.` (flat layout)",
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
]
|
|
}
|
|
},
|
|
"additionalProperties": false
|
|
},
|
|
"TerminalOptions": {
|
|
"type": "object",
|
|
"properties": {
|
|
"error-on-warning": {
|
|
"description": "Use exit code 1 if there are any warning-level diagnostics.\n\nDefaults to `false`.",
|
|
"type": [
|
|
"boolean",
|
|
"null"
|
|
]
|
|
},
|
|
"output-format": {
|
|
"description": "The format to use for printing diagnostic messages.\n\nDefaults to `full`.",
|
|
"anyOf": [
|
|
{
|
|
"$ref": "#/definitions/DiagnosticFormat"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"additionalProperties": false
|
|
}
|
|
}
|
|
} |