Python Type Hint Generator – Add Hints from Defaults
NOVOPython type hint generator that adds annotations inferred from default values and simple return statements, with typing imports and a before/after view. Free, in-browser.
Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.
Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.
from typing import Any
def paginate(items, page: int = 1, per_page: float = 20.0, label: str = "Page", is_last: bool | None = None) -> list[Any] | list[str | int]:
if not items:
return []
return [label, page]
def is_valid(code: str = "") -> bool:
return len(code) == 6
class Cart:
def __init__(self, items: list[Any] = [], discount: float = 0.0) -> None:
self.items = items
| Function | Target | Type | Because |
|---|---|---|---|
| paginate | page | int | default 1 |
| paginate | per_page | float | default 20.0 |
| paginate | label | str | default "Page" |
| paginate | is_last | bool | None | default None + name prefix is_ |
| paginate | return | list[Any] | list[str | int] | return [] / [label, page] |
| is_valid | code | str | default "" |
| is_valid | return | bool | return len(code) == 6 |
| Cart.__init__ | items | list[Any] | default [] |
| Cart.__init__ | discount | float | default 0.0 |
| Cart.__init__ | return | None | __init__ always returns None |
Not inferred (1) — annotate these yourself:
- paginate · items: no default to infer from
- Cart.__init__(items=[]): mutable default argument — the same object is shared between calls; consider None and create it inside the function.
Inference is heuristic: it only reads literal defaults, a few name prefixes and simple return expressions. Run mypy or pyright on the result.
Exemplos rápidos
Entradas típicas e os resultados que esta ferramenta gera.
Visão geral
This Python type hint generator adds annotations to functions that have none. It looks at evidence that is actually in the code: literal default values (numbers, strings, bytes, booleans, lists, dicts, sets, tuples, lambdas), a short list of boolean name prefixes such as is_ and has_, and the expressions in simple return statements. Existing annotations are never changed.
You choose modern syntax (list[int], X | None, Python 3.10+) or the typing module (List[int], Optional[X]) for older code, and the tool adds the matching from typing import line and, optionally, from __future__ import annotations. A before/after view and a table explain where each hint came from.
Inference is a heuristic, not a type checker. Anything it cannot prove is listed under "Not inferred" instead of guessed, and you should still run mypy or pyright. Everything runs in your browser.
Por que usar esta ferramenta?
- Annotate legacy functions in seconds
- Every hint comes with the reason it was added
- Modern or typing-module syntax with imports
- Never guesses silently — unknowns are listed
- Warns about mutable default arguments
Recursos
Hints from defaults
int, float, complex, str, bytes, bool and nested list/dict/set/tuple literals become precise types.
Return types
Simple returns (literals, comparisons, len(), str(), parameters) are combined into one return type, None included.
Two syntaxes
list[int] and X | None for 3.10+, or List[int] and Optional[X] with the typing module.
Import lines
Adds from typing / collections.abc imports after the module docstring and __future__ imports.
Before / after
Switch views and read a table of every added hint and its reason.
Honest gaps
Parameters and returns with no usable evidence are listed, or annotated as Any if you opt in.
Como usar
Paste functions
Put one or more Python functions (with their bodies) into the Python functions box.
Pick the syntax
Choose Modern or typing module, and the import and name-prefix options.
Review the table
Check the Added hints table and the Not inferred list.
Copy the code
Press Copy annotated code and run your type checker on it.