-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocols.py
49 lines (38 loc) · 918 Bytes
/
protocols.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
This module demonstrates the use of duck typing protocols
"""
import time
from typing import Protocol
class Switchable(Protocol):
def turn_on(self):
"""Turns this item on
Should perform the action of turning on
"""
...
def turn_off(self):
"""Turns this item off
Should perform the action of turning off
"""
...
class LightSwitch:
"""
A simple light switch
"""
def turn_on(self):
print('Flicking switch on')
def turn_off(self):
print('Flicking switch off')
class FootSwitch:
"""
A foot activated switch
"""
def turn_on(self):
"""
Happens when the switch is stepped on
"""
print('Stepping on switch')
def turn_off(self):
"""
Happens when the switch is stepped off
"""
print('Stepping off switch')