Skip to content

Commit

Permalink
new tip
Browse files Browse the repository at this point in the history
  • Loading branch information
bbelderbos committed Jul 26, 2024
1 parent e210cd5 commit 110f0ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ This file gets generated by [this script](index.py).
- [Integer division](notes/20221203175534.md)
- [Type() vs isinstance()](notes/20240117112801.md)

## Typing

- [You can now use | for typing](notes/20240726111223.md)

## Unix

- [How to read from standard input (stdin) in python?](notes/20230829192509.md)
Expand Down
23 changes: 23 additions & 0 deletions notes/20240726111223.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# You can now use | for typing

`|` got added to type hints >= 3.10, not needing the `typing` import anymore:

- Unions can now be written as `X | Y`
- Optional can now be written as `X | None`

```
typing import Union, Optional
def func(x: Union[int, str]) -> Optional[int]:
pass
# >= 3.10
# no more typing import needed
def func(x: int | str) -> int | None:
pass
```

#typing

0 comments on commit 110f0ee

Please sign in to comment.