Skip to content

Commit 605c18d

Browse files
committed
python typing add decorator and overload
1 parent a9c378b commit 605c18d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/posts/2025/2025-02-01-python-type-hints.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ def f() -> AliasType:
175175
...
176176
```
177177

178+
!!! warning "type alias can not be used with isinstance()"
179+
178180
## Type variable
179181

180182
[From MyPy](https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-type-of-class-objects): Python 3.12 introduced new syntax to use the `type[C]` and a type variable with an upper bound (see [Type variables with upper bounds](https://mypy.readthedocs.io/en/stable/generics.html#type-variable-upper-bound)).
@@ -537,6 +539,17 @@ concat(b'a', b'b') # Okay
537539
concat(1, 2) # Error!
538540
```
539541

542+
### Annotating decorators
543+
544+
<https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators>
545+
546+
## Overloading
547+
548+
Use [@overload](https://mypy.readthedocs.io/en/stable/more_types.html#function-overloading) to let type checkers know that a function can accept different types of arguments and return different types based on those arguments.
549+
550+
!!! note "If there are multiple equally good matching variants (overloaded functions), mypy will select the variant that was defined first."
551+
Put always the finest overloaded function at first: https://mypy.readthedocs.io/en/stable/more_types.html#type-checking-the-variants
552+
540553
## Typing tools
541554

542555
### MyPy

0 commit comments

Comments
 (0)