How to Type Hint a Python Function That Returns Nothing with -> None
Some functions do a job and hand nothing back: they print, save a file or send a message. In a type hint, you say so with -> None after the parameters. This guide writes one such function on Python 3.15.2 and looks at what Python does with the hint.
Syntax
def <name>(<parameters>) -> None:
<body with no return value>
| Part | What it means |
|---|---|
<name>(<parameters>) | The function and its parameters, with their own hints if you like, such as name: str |
-> None | Says the function returns no value |
<body with no return value> | Code that does its job without return <value>. A bare return, or none at all, returns None |
The typing specification says: "When used in a type hint, the expression None is considered equivalent to type(None)." A function that ends without returning a value gives back None, so -> None describes it exactly.
The Example
greet() prints a greeting and returns nothing. The script calls it, prints what the call returned, and prints the hints Python stored on the function.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
def greet(name: str) -> None:
print(f"Hello, {name}!")
result = greet("Ana")
print(result)
print(greet.__annotations__)

-> Nonecomes after the closing parenthesis and before the colon.resultcatches what the call returns.greet.__annotations__is the dictionary of hints Python keeps on the function.
Step 2: Run It
uv run python greet.py
Hello, Ana!
None
{'name': <class 'str'>, 'return': None}

The function printed its greeting, the call returned None, and Python stored the hint under the key 'return'. The hint changes nothing when the program runs: it tells readers, editors and type checkers what to expect. The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Writing none in lowercase: -> none | The function still runs, but reading its hints fails with NameError: name 'none' is not defined. Did you mean: 'None'? | Write None with a capital N |
Returning a value from a -> None function | Python doesn't check: return f"Hello, {name}!" under -> None runs, and the caller gets the text | Fix the hint to the real type, such as -> str, or stop returning the value |
| Leaving the hint out of the other functions in a file that uses hints | Readers and tools can't tell "returns nothing" from "not annotated yet" | Write -> None on every function that returns nothing |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
NameError only when something reads the hints | A misspelled name in a hint. Since Python 3.14, hints are evaluated when they're read, not when the function is defined | Correct the spelling |
The function returns None when you expected a value | It has no return <value> | Add the return, and change the hint to match |
FAQ
Do I have to write -> None?
No. Hints are optional, and the function works the same without it. Write it when the rest of your code has hints, so "returns nothing" is said rather than guessed.
Why did the misspelled none not fail straight away?
Since Python 3.14, annotations are evaluated lazily. The language reference says "they are not evaluated when the code containing the annotation is evaluated." In the run above, greet("Ana") printed Hello, Ana!, and the NameError came only when the script read greet.__annotations__.
Conclusion
def greet(name: str) -> None: said the function returns nothing. The call returned None, and Python stored the hint as 'return': None without checking it. Spell it with a capital N, and keep it true.
Additional Resources
- The typing specification: None —
Nonein type hints. - Function definitions — where the
->part goes. - Annotations — lazy evaluation since Python 3.14.
