-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinals.py
More file actions
25 lines (18 loc) · 715 Bytes
/
finals.py
File metadata and controls
25 lines (18 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from typing_extensions import Final, final
cannot_change_me: Final = "cannot change me"
cannot_change_me = "trying to change me" # error: Cannot assign to final name "cannot_change_me"
print(cannot_change_me) # trying to change me
integer1: Final[int] = 42
integer1 = 66 # error: Cannot assign to final name "integer1"
class Base:
@final
def base_method(self) -> int:
...
class Derived(Base):
def base_method(self) -> int: # error: Cannot override final attribute "base_method" (previously declared in base class "Base")
...
@final
class CannotBeSubclassed:
...
class TryToDeriveFrom(CannotBeSubclassed): # error: Cannot inherit from final class "CannotBeSubclassed"
...