|
390 | 390 | } |
391 | 391 | ] |
392 | 392 | }, |
393 | | - "byte-string-type-annotation": { |
394 | | - "title": "detects byte strings in type annotation positions", |
395 | | - "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 analyze 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```", |
396 | | - "default": "error", |
397 | | - "oneOf": [ |
398 | | - { |
399 | | - "$ref": "#/definitions/Level" |
400 | | - } |
401 | | - ] |
402 | | - }, |
403 | 393 | "call-abstract-method": { |
404 | 394 | "title": "detects calls to abstract methods with trivial bodies on class objects", |
405 | 395 | "description": "## What it does\nChecks for calls to abstract `@classmethod`s or `@staticmethod`s\nwith \"trivial bodies\" when accessed on the class object itself.\n\n\"Trivial bodies\" are bodies that solely consist of `...`, `pass`,\na docstring, and/or `raise NotImplementedError`.\n\n## Why is this bad?\nAn abstract method with a trivial body has no concrete implementation\nto execute, so calling such a method directly on the class will probably\nnot have the desired effect.\n\nIt is also unsound to call these methods directly on the class. Unlike\nother methods, ty permits abstract methods with trivial bodies to have\nnon-`None` return types even though they always return `None` at runtime.\nThis is because it is expected that these methods will always be\noverridden rather than being called directly. As a result of this\nexception to the normal rule, ty may infer an incorrect type if one of\nthese methods is called directly, which may then mean that type errors\nelsewhere in your code go undetected by ty.\n\nCalling abstract classmethods or staticmethods via `type[X]` is allowed,\nsince the actual runtime type could be a concrete subclass with an implementation.\n\n## Example\n```python\nfrom abc import ABC, abstractmethod\n\nclass Foo(ABC):\n @classmethod\n @abstractmethod\n def method(cls) -> int: ...\n\nFoo.method() # Error: cannot call abstract classmethod\n```", |
|
570 | 560 | } |
571 | 561 | ] |
572 | 562 | }, |
573 | | - "fstring-type-annotation": { |
574 | | - "title": "detects F-strings in type annotation positions", |
575 | | - "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 analyze 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```", |
576 | | - "default": "error", |
577 | | - "oneOf": [ |
578 | | - { |
579 | | - "$ref": "#/definitions/Level" |
580 | | - } |
581 | | - ] |
582 | | - }, |
583 | 563 | "ignore-comment-unknown-rule": { |
584 | 564 | "title": "detects `ty: ignore` comments that reference unknown rules", |
585 | 565 | "description": "## What it does\nChecks for `ty: ignore[code]` or `type: ignore[ty:code]` comments where `code` isn't a known lint rule.\n\n## Why is this bad?\nA `ty: ignore[code]` or a `type:ignore[ty: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```", |
|
1060 | 1040 | } |
1061 | 1041 | ] |
1062 | 1042 | }, |
| 1043 | + "invalid-typed-dict-field": { |
| 1044 | + "title": "detects invalid `TypedDict` field declarations", |
| 1045 | + "description": "## What it does\nDetects invalid `TypedDict` field declarations.\n\n## Why is this bad?\n`TypedDict` subclasses cannot redefine inherited fields incompatibly. Doing so breaks the\nsubtype guarantees that `TypedDict` inheritance is meant to preserve.\n\n## Example\n```python\nfrom typing import TypedDict\n\nclass Base(TypedDict):\n x: int\n\nclass Child(Base):\n x: str # error: [invalid-typed-dict-field]\n```", |
| 1046 | + "default": "error", |
| 1047 | + "oneOf": [ |
| 1048 | + { |
| 1049 | + "$ref": "#/definitions/Level" |
| 1050 | + } |
| 1051 | + ] |
| 1052 | + }, |
1063 | 1053 | "invalid-typed-dict-header": { |
1064 | 1054 | "title": "detects invalid statements in `TypedDict` class headers", |
1065 | 1055 | "description": "## What it does\nDetects errors in `TypedDict` class headers, such as unexpected arguments\nor invalid base classes.\n\n## Why is this bad?\nThe typing spec states that `TypedDict`s are not permitted to have\ncustom metaclasses. Using `**` unpacking in a `TypedDict` header\nis also prohibited by ty, as it means that ty cannot statically determine\nwhether keys in the `TypedDict` are intended to be required or optional.\n\n## Example\n```python\nfrom typing import TypedDict\n\nclass Foo(TypedDict, metaclass=whatever): # error: [invalid-typed-dict-header]\n ...\n\ndef f(x: dict):\n class Bar(TypedDict, **x): # error: [invalid-typed-dict-header]\n ...\n```", |
|
0 commit comments