DEVELOPER TOOL
Python Type Hint Generator
Add type hints to a Python function signature, inferred from default values.
About this tool
Paste an untyped (or partially typed) function signature and get type hints inferred from each parameter's default value — times=1 becomes times: int = 1, verbose=False becomes verbose: bool = False, and so on. Parameters that already have a hint are left untouched.
Frequently asked questions
- How are types inferred?
- From the literal type of each default value: numbers become
int/float, quoted text becomesstr,True/Falsebecomesbool,[...]becomeslist,{...}becomesdict, andNonebecomesOptional[Any](there's no way to know the "real" type fromNonealone). - What happens to parameters with no default value?
- They're hinted as
Any, since there's no literal to infer a type from — replace it with the real type once you know it. - Does this figure out the return type automatically?
- No — inferring a return type requires analyzing the function body (what it actually returns), which this tool doesn't do. Enter one manually if you know it, or leave it blank to omit the return annotation.