Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
## Python How-To Examples
by Chaiyawut Thengket
by Chaiyawut Thengket

we
rtferw
gtewr
tgerw
tgerw
t
ewt
wre
18 changes: 18 additions & 0 deletions self-referencing-hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Self-Referencing Type Hints

Inside of a class, if you write a type hint that refers to the same class Python will raise an Error because the class is not known yet.
For example:
```python
class Money:
def __add__(self, other: Money) -> Money: # ERROR: Money is unknown
"""Return the sum of two money objects."""
... (code omitted)
```

to fix this, add the following import:
```python
from __future__ import annotations

class Money:
def __add__(self, other: Money) -> Money: # OK!
```