Skip to content

Commit 15933d9

Browse files
committed
Refactoring. Adding the None annotation to the return value
1 parent 827ea62 commit 15933d9

27 files changed

Lines changed: 48 additions & 48 deletions

File tree

‎Sorting algorithm list/comparison_of_sorting.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class Kill(Exception):
1515

1616

1717
class KThread(Thread):
18-
def __init__(self, *args, **keywords):
18+
def __init__(self, *args, **keywords) -> None:
1919
Thread.__init__(self, *args, **keywords)
2020
self.killed = False
2121

22-
def start(self):
22+
def start(self) -> None:
2323
"""Start the thread."""
2424
self.__run_backup = self.run
2525
self.run = self.__run # Force the Thread to install our trace.
2626
Thread.start(self)
2727

28-
def __run(self):
28+
def __run(self) -> None:
2929
"""Hacked run function, which installs the
3030
trace."""
3131
sys.settrace(self.globaltrace)
@@ -48,7 +48,7 @@ def localtrace(self, frame, why, arg):
4848
raise Kill()
4949
return self.localtrace
5050

51-
def kill(self):
51+
def kill(self) -> None:
5252
self.killed = True
5353

5454

@@ -88,7 +88,7 @@ def the_wrapper_around_the_original_function(*args, **kwargs):
8888
print(name)
8989

9090
@timeout(seconds=10, raise_timeout=True)
91-
def run():
91+
def run() -> None:
9292
new_items = list(items)
9393
algo(new_items)
9494

‎Sorting algorithm list/sorts/bogosort.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def bogosort(collection):
2626
[-45, -5, -2]
2727
"""
2828

29-
def isSorted(collection):
29+
def isSorted(collection) -> bool:
3030
if len(collection) < 2:
3131
return True
3232
for i in range(len(collection) - 1):

‎Sorting algorithm list/sorts/heap_sort.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from __future__ import print_function
1414

1515

16-
def heapify(unsorted, index, heap_size):
16+
def heapify(unsorted, index, heap_size) -> None:
1717
largest = index
1818
left_index = 2 * index + 1
1919
right_index = 2 * index + 2

‎Sorting/sorting.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424

2525

2626
class Student:
27-
def __init__(self, name, age):
27+
def __init__(self, name, age) -> None:
2828
self.name = name
2929
self.age = age
3030

31-
def __repr__(self):
31+
def __repr__(self) -> str:
3232
return "%s (%d)" % (self.name, self.age)
3333

3434

‎sirena_parser/main.py‎

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

99

1010
class SirenaRecord:
11-
def __init__(self, line: str):
11+
def __init__(self, line: str) -> None:
1212
self.values: list[str] = []
1313
self.type = line[0]
1414

@@ -48,7 +48,7 @@ def __init__(self, line: str):
4848

4949

5050
class SirenaMessage:
51-
def __init__(self, queue_lines: list[str]):
51+
def __init__(self, queue_lines: list[str]) -> None:
5252
self.lines: list[str] = []
5353
self.records: list[SirenaRecord] = []
5454

@@ -71,7 +71,7 @@ def __init__(self, queue_lines: list[str]):
7171

7272

7373
class SirenaFile:
74-
def __init__(self, file_name: str):
74+
def __init__(self, file_name: str) -> None:
7575
self.lines: list[str] = []
7676
self.queue_lines: list[str] = []
7777
self.messages: list[SirenaMessage] = []

‎socket__tcp__examples/common.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def crc32_from_bytes(data: bytes) -> int:
1515
return zlib.crc32(data) & 0xFFFFFFFF
1616

1717

18-
def send_msg__with_crc32(sock, msg):
18+
def send_msg__with_crc32(sock, msg) -> None:
1919
# Prefix each message with a 12-byte (network byte order) length: 8-byte data length and 4-byte crc32 data
2020
crc32 = crc32_from_bytes(msg)
2121
msg = struct.pack(">QI", len(msg), crc32) + msg
@@ -47,7 +47,7 @@ def recv_msg__with_crc32(sock) -> bytes | None:
4747
return msg
4848

4949

50-
def send_msg(sock, msg, msg_len_format: str = ">Q"):
50+
def send_msg(sock, msg, msg_len_format: str = ">Q") -> None:
5151
# Prefix each message with a 8-byte (>Q) length (network byte order)
5252
msg = struct.pack(msg_len_format, len(msg)) + msg
5353
sock.sendall(msg)

‎socket__tcp__examples/hello_world__using_socketserver/server.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MyTCPHandler(socketserver.BaseRequestHandler):
2626
client.
2727
"""
2828

29-
def handle(self):
29+
def handle(self) -> None:
3030
print("Connected:", self.client_address)
3131

3232
data = recv_msg(self.request)

‎socket__tcp__examples/hello_world__with_RSA_AES__commands_in_JSON__client=private_and_server=public/server.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def process_command(data: bytes, conn, addr) -> bytes:
6464
return json.dumps(rq, ensure_ascii=False).encode("utf-8")
6565

6666

67-
def process_connect(conn, addr):
67+
def process_connect(conn, addr) -> None:
6868
print(f"[+] New connection from {addr}")
6969

7070
try:

‎socket__tcp__examples/hello_world__with_RSA_AES__commands_in_JSON__client=public_and_server=private/server.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def process_command(data: bytes, conn, addr) -> bytes:
5151
return json.dumps(rq, ensure_ascii=False).encode("utf-8")
5252

5353

54-
def process_connect(conn, addr):
54+
def process_connect(conn, addr) -> None:
5555
print(f"[+] New connection from {addr}")
5656

5757
try:

‎socket__tcp__examples/http_server.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import socket
1111

1212

13-
def send_answer(conn, status="200 OK", typ="text/plain; charset=utf-8", data=""):
13+
def send_answer(conn, status="200 OK", typ="text/plain; charset=utf-8", data="") -> None:
1414
data = data.encode("utf-8")
1515

1616
conn.send(b"GET HTTP/1.1 " + status.encode("utf-8") + b"\r\n")
@@ -22,7 +22,7 @@ def send_answer(conn, status="200 OK", typ="text/plain; charset=utf-8", data="")
2222
conn.send(data)
2323

2424

25-
def parse(conn): # Обработка соединения в отдельной функции
25+
def parse(conn) -> None: # Обработка соединения в отдельной функции
2626
data = b""
2727

2828
while b"\r\n" not in data: # Ждём первую строку

0 commit comments

Comments
 (0)