Skip to content

Commit a7ae380

Browse files
committed
Refactoring. design_patterns__examples/. Adding the None annotation to the return value
1 parent 3ca1d3a commit a7ae380

42 files changed

Lines changed: 334 additions & 313 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎design_patterns__examples/Abstract Factory/example.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ def create_button(self) -> IButton:
4040

4141

4242
class WinLabel(ILabel):
43-
def paint(self):
43+
def paint(self) -> None:
4444
print("WinLabel")
4545

4646

4747
class OSXLabel(ILabel):
48-
def paint(self):
48+
def paint(self) -> None:
4949
print("OSXLabel")
5050

5151

5252
class WinButton(IButton):
53-
def paint(self):
53+
def paint(self) -> None:
5454
print("WinButton")
5555

5656

5757
class OSXButton(IButton):
58-
def paint(self):
58+
def paint(self) -> None:
5959
print("OSXButton")
6060

6161

‎design_patterns__examples/Adapter/example__using_composition.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@ def get_picture(self):
1818

1919

2020
class GameConsole:
21-
def create_game_picture(self):
21+
def create_game_picture(self) -> str:
2222
return "picture from console"
2323

2424

2525
class Antenna:
26-
def create_wave_picture(self):
26+
def create_wave_picture(self) -> str:
2727
return "picture from wave"
2828

2929

3030
class SourceGameConsoleAdapter(SourceAdapter):
31-
def __init__(self, game_console: GameConsole):
31+
def __init__(self, game_console: GameConsole) -> None:
3232
self.game_console = game_console
3333

3434
def get_picture(self):
3535
return self.game_console.create_game_picture()
3636

3737

3838
class SourceAntennaAdapter(SourceAdapter):
39-
def __init__(self, antenna: Antenna):
39+
def __init__(self, antenna: Antenna) -> None:
4040
self.antenna = antenna
4141

4242
def get_picture(self):
4343
return self.antenna.create_wave_picture()
4444

4545

4646
class TV:
47-
def __init__(self, source: SourceAdapter):
47+
def __init__(self, source: SourceAdapter) -> None:
4848
self.source = source
4949

5050
def show_picture(self):

‎design_patterns__examples/Adapter/example__using_inheritance.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def get_picture(self):
1818

1919

2020
class GameConsole:
21-
def create_game_picture(self):
21+
def create_game_picture(self) -> str:
2222
return "picture from console"
2323

2424

2525
class Antenna:
26-
def create_wave_picture(self):
26+
def create_wave_picture(self) -> str:
2727
return "picture from wave"
2828

2929

@@ -38,7 +38,7 @@ def get_picture(self):
3838

3939

4040
class TV:
41-
def __init__(self, source: SourceAdapter):
41+
def __init__(self, source: SourceAdapter) -> None:
4242
self.source = source
4343

4444
def show_picture(self):

‎design_patterns__examples/Bridge/example_1/devices/radio.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99

1010
class Radio(Device):
11-
def __init__(self):
11+
def __init__(self) -> None:
1212
self._on = False
1313
self._volume = 30
1414
self._channel = 1
1515

1616
def is_enabled(self) -> bool:
1717
return self._on
1818

19-
def enable(self):
19+
def enable(self) -> None:
2020
self._on = True
2121

22-
def disable(self):
22+
def disable(self) -> None:
2323
self._on = False
2424

2525
def get_volume(self) -> int:
2626
return self._volume
2727

28-
def set_volume(self, volume: int):
28+
def set_volume(self, volume: int) -> None:
2929
if volume > 100:
3030
self._volume = 100
3131
elif volume < 0:
@@ -36,10 +36,10 @@ def set_volume(self, volume: int):
3636
def get_channel(self) -> int:
3737
return self._channel
3838

39-
def set_channel(self, channel: int):
39+
def set_channel(self, channel: int) -> None:
4040
self._channel = channel
4141

42-
def print_status(self):
42+
def print_status(self) -> None:
4343
print("------------------------------------")
4444
print("| I'm radio.")
4545
print("| I'm " + ("enabled" if self._on else "disabled"))

‎design_patterns__examples/Bridge/example_1/devices/tv.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99

1010
class Tv(Device):
11-
def __init__(self):
11+
def __init__(self) -> None:
1212
self._on = False
1313
self._volume = 30
1414
self._channel = 1
1515

1616
def is_enabled(self) -> bool:
1717
return self._on
1818

19-
def enable(self):
19+
def enable(self) -> None:
2020
self._on = True
2121

22-
def disable(self):
22+
def disable(self) -> None:
2323
self._on = False
2424

2525
def get_volume(self) -> int:
2626
return self._volume
2727

28-
def set_volume(self, volume: int):
28+
def set_volume(self, volume: int) -> None:
2929
if volume > 100:
3030
self._volume = 100
3131
elif volume < 0:
@@ -36,10 +36,10 @@ def set_volume(self, volume: int):
3636
def get_channel(self) -> int:
3737
return self._channel
3838

39-
def set_channel(self, channel: int):
39+
def set_channel(self, channel: int) -> None:
4040
self._channel = channel
4141

42-
def print_status(self):
42+
def print_status(self) -> None:
4343
print("------------------------------------")
4444
print("| I'm TV set.")
4545
print("| I'm " + ("enabled" if self._on else "disabled"))

‎design_patterns__examples/Bridge/example_1/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from remotes.advanced_remote import AdvancedRemote
1818

1919

20-
def test_device(device):
20+
def test_device(device) -> None:
2121
print("Tests with basic remote.")
2222
basic_remote = BasicRemote(device)
2323
basic_remote.power()

‎design_patterns__examples/Bridge/example_1/remotes/advanced_remote.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
class AdvancedRemote(BasicRemote):
1111
"""Улучшенный пульт"""
1212

13-
def mute(self):
13+
def mute(self) -> None:
1414
print("Remote: mute")
1515
self._device.set_volume(0)

‎design_patterns__examples/Bridge/example_1/remotes/basic_remote.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@
1111
class BasicRemote(Remote):
1212
"""Стандартный пульт"""
1313

14-
def __init__(self, device: Device):
14+
def __init__(self, device: Device) -> None:
1515
self._device = device
1616

17-
def power(self):
17+
def power(self) -> None:
1818
print("Remote: power toggle")
1919
if self._device.is_enabled():
2020
self._device.disable()
2121
else:
2222
self._device.enable()
2323

24-
def volume_down(self):
24+
def volume_down(self) -> None:
2525
print("Remote: volume down")
2626
self._device.set_volume(self._device.get_volume() - 10)
2727

28-
def volume_up(self):
28+
def volume_up(self) -> None:
2929
print("Remote: volume up")
3030
self._device.set_volume(self._device.get_volume() + 10)
3131

32-
def channel_down(self):
32+
def channel_down(self) -> None:
3333
print("Remote: channel down")
3434
self._device.set_channel(self._device.get_channel() - 1)
3535

36-
def channel_up(self):
36+
def channel_up(self) -> None:
3737
print("Remote: channel up")
3838
self._device.set_channel(self._device.get_channel() + 1)

‎design_patterns__examples/Bridge/example_2.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def draw_circle(self, x: int, y: int, radius: int):
2020
class SmallCircleDrawer(Drawer):
2121
RADIUS_MULTIPLIER = 0.25
2222

23-
def draw_circle(self, x: int, y: int, radius: int):
23+
def draw_circle(self, x: int, y: int, radius: int) -> None:
2424
print(
2525
f"Small circle center = {x},{y} radius = {radius * self.RADIUS_MULTIPLIER}"
2626
)
@@ -29,37 +29,37 @@ def draw_circle(self, x: int, y: int, radius: int):
2929
class LargeCircleDrawer(Drawer):
3030
RADIUS_MULTIPLIER = 10
3131

32-
def draw_circle(self, x: int, y: int, radius: int):
32+
def draw_circle(self, x: int, y: int, radius: int) -> None:
3333
print(
3434
f"Large circle center = {x},{y} radius = {radius * self.RADIUS_MULTIPLIER}"
3535
)
3636

3737

3838
class Shape(ABC):
39-
def __init__(self, drawer: Drawer):
39+
def __init__(self, drawer: Drawer) -> None:
4040
self._drawer = drawer
4141

4242
@abstractmethod
43-
def draw(self):
43+
def draw(self) -> None:
4444
pass
4545

4646
@abstractmethod
47-
def enlarge_radius(self, multiplier: int):
47+
def enlarge_radius(self, multiplier: int) -> None:
4848
pass
4949

5050

5151
class Circle(Shape):
52-
def __init__(self, x: int, y: int, radius: int, drawer: Drawer):
52+
def __init__(self, x: int, y: int, radius: int, drawer: Drawer) -> None:
5353
super().__init__(drawer)
5454

5555
self._x = x
5656
self._y = y
5757
self._radius = radius
5858

59-
def draw(self):
59+
def draw(self) -> None:
6060
self._drawer.draw_circle(self._x, self._y, self._radius)
6161

62-
def enlarge_radius(self, multiplier: int):
62+
def enlarge_radius(self, multiplier: int) -> None:
6363
self._radius *= multiplier
6464

6565
def get_x(self) -> int:
@@ -71,13 +71,13 @@ def get_y(self) -> int:
7171
def get_radius(self) -> int:
7272
return self._radius
7373

74-
def set_x(self, x: int):
74+
def set_x(self, x: int) -> None:
7575
self._x = x
7676

77-
def set_y(self, y: int):
77+
def set_y(self, y: int) -> None:
7878
self._y = y
7979

80-
def set_radius(self, radius: int):
80+
def set_radius(self, radius: int) -> None:
8181
self._radius = radius
8282

8383

0 commit comments

Comments
 (0)