Skip to content

Commit 044af7f

Browse files
authored
FAQ: Why doesn't ty warn about missing type annotations? (#2721)
## Summary This came up multiple times on our issue tracker (#476 and duplicates thereof).
1 parent eb43dff commit 044af7f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

docs/reference/typing-faq.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,33 @@ Not yet. A stricter inference mode is tracked in
175175
[`flake8-annotations` rules](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) to enforce
176176
more explicit type annotations in your code.
177177

178+
## Why doesn't ty warn about missing type annotations?
179+
180+
ty does not report an error for unannotated function parameters, return types, or variables. When
181+
ty encounters an unannotated symbol, it infers the type as [`Unknown`](#what-is-the-unknown-type-and-when-does-it-appear)
182+
while still providing useful diagnostics where possible.
183+
184+
If you are looking for the equivalent of mypy's
185+
[`disallow_untyped_defs`](https://mypy.readthedocs.io/en/stable/config_file.html#confval-disallow_untyped_defs)
186+
(error code: `no-untyped-def`), Ruff provides this as a set of opt-in lint rules via its
187+
[`flake8-annotations` (`ANN`)](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) rule
188+
group.
189+
190+
Some rules you might find useful include:
191+
192+
- [`ANN001`](https://docs.astral.sh/ruff/rules/missing-type-function-argument/): Missing type
193+
annotation for function argument
194+
- [`ANN002`](https://docs.astral.sh/ruff/rules/missing-type-args/): Missing type annotation for
195+
`*args`
196+
- [`ANN003`](https://docs.astral.sh/ruff/rules/missing-type-kwargs/): Missing type annotation for
197+
`**kwargs`
198+
- [`ANN201`](https://docs.astral.sh/ruff/rules/missing-return-type-undocumented-public-function/):
199+
Missing return type annotation for public function
200+
- [`ANN202`](https://docs.astral.sh/ruff/rules/missing-return-type-private-function/): Missing
201+
return type annotation for private function
202+
- [`RUF045`](https://docs.astral.sh/ruff/rules/implicit-class-var-in-dataclass/): Implicit class
203+
variable in dataclass
204+
178205
## Why can't ty resolve my imports?
179206

180207
Import resolution issues are often caused by a missing or incorrect environment configuration. When

0 commit comments

Comments
 (0)