Skip to content

Commit d427e7f

Browse files
authored
Create typing-final.md
1 parent 2be04b3 commit d427e7f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

python/typing-final.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# `typing.final`
2+
3+
## Links
4+
5+
- [Python docs: `typing.final`](https://docs.python.org/3/library/typing.html#typing.final)
6+
7+
Adding the `@final` decorator to a class or class method indicates that the object cannot be overridden. You can't subclass that class and you can't override that method in a subclass.
8+
9+
You can add it to either a class or a method on a class.
10+
11+
Example from the docs:
12+
13+
```python
14+
class Base:
15+
@final
16+
def done(self) -> None:
17+
...
18+
class Sub(Base):
19+
def done(self) -> None: # Error reported by type checker
20+
...
21+
22+
@final
23+
class Leaf:
24+
...
25+
class Other(Leaf): # Error reported by type checker
26+
...
27+
```

0 commit comments

Comments
 (0)