⚡
usefultools.dev
T:

Python Type Hint Generator – Add Hints from Defaults

NOVO

Python 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
Added hints (10)
FunctionTargetTypeBecause
paginatepageintdefault 1
paginateper_pagefloatdefault 20.0
paginatelabelstrdefault "Page"
paginateis_lastbool | Nonedefault None + name prefix is_
paginatereturnlist[Any] | list[str | int]return [] / [label, page]
is_validcodestrdefault ""
is_validreturnboolreturn len(code) == 6
Cart.__init__itemslist[Any]default []
Cart.__init__discountfloatdefault 0.0
Cart.__init__returnNone__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.

Default
page=1
page: int = 1
Tuple
a=(1, "a")
a: tuple[int, str] = (1, "a")
Name
is_active=None
is_active: bool | None = None
Return
return x > 0
-> bool
typing
items=[]
items: List[Any] = []
📖

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

1

Paste functions

Put one or more Python functions (with their bodies) into the Python functions box.

2

Pick the syntax

Choose Modern or typing module, and the import and name-prefix options.

3

Review the table

Check the Added hints table and the Not inferred list.

4

Copy the code

Press Copy annotated code and run your type checker on it.

🤔

Perguntas frequentes