Skip to content

Commit 85e8047

Browse files
committed
Refactoring. Adding the None annotation to the return value
1 parent bfe5f57 commit 85e8047

15 files changed

Lines changed: 32 additions & 32 deletions

File tree

‎regexp_examples/sub__with_callback_on_match.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
counter = 3000 - 1
3838

3939

40-
def on_sub(_):
40+
def on_sub(_) -> str:
4141
global counter
4242
counter += 1
4343

‎remove_comments_from_python_code/clear_code.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def clear_code(
4747
return astunparse.unparse(tree)
4848

4949

50-
def clear_file(file_name: str, new_file_name: str = None, encoding="utf-8"):
50+
def clear_file(file_name: str, new_file_name: str = None, encoding="utf-8") -> None:
5151
if new_file_name is None:
5252
new_file_name = file_name
5353

@@ -58,7 +58,7 @@ def clear_file(file_name: str, new_file_name: str = None, encoding="utf-8"):
5858
f.write(text)
5959

6060

61-
def clear_directory(dir_path: str):
61+
def clear_directory(dir_path: str) -> None:
6262
new_dir_path = Path(dir_path + "_copy_clear")
6363

6464
shutil.rmtree(new_dir_path, ignore_errors=True)

‎requests__examples/pastebin3_requests.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def paste(
145145
return rs.text
146146

147147

148-
def delete_paste(dev_key, user_key, paste_key):
148+
def delete_paste(dev_key, user_key, paste_key) -> bool:
149149
"""Deleting A Paste Created By A User
150150
151151
:param dev_key:

‎requests__examples/prodobavki.com_dobavki__print_info.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from bs4 import BeautifulSoup
1111

1212

13-
def print_info(url):
13+
def print_info(url) -> None:
1414
rs = requests.get(url)
1515
root = BeautifulSoup(rs.content, "lxml")
1616

‎rumble (vibration) a xbox 360 controller/gui.py‎

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

1212

1313
class MainWindow(QMainWindow):
14-
def __init__(self):
14+
def __init__(self) -> None:
1515
super().__init__()
1616

1717
self.setWindowTitle("Rumble (vibration) a xbox 360 controller")
@@ -68,14 +68,14 @@ def __init__(self):
6868
central_widget.setLayout(layout)
6969
self.setCentralWidget(central_widget)
7070

71-
def _enable_vibration(self, enable):
71+
def _enable_vibration(self, enable) -> None:
7272
if enable:
7373
self.timer.start()
7474
else:
7575
self.timer.stop()
7676
set_vibration(0, 0)
7777

78-
def _timeout(self):
78+
def _timeout(self) -> None:
7979
set_vibration(self.left_motor.value(), self.right_motor.value())
8080

8181

‎rumble (vibration) a xbox 360 controller/rumble.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class XINPUT_VIBRATION(ctypes.Structure):
2828
XInputSetState.restype = ctypes.c_uint
2929

3030

31-
def set_vibration(left_motor, right_motor, controller=0):
31+
def set_vibration(left_motor, right_motor, controller=0) -> None:
3232
if type(left_motor) == float:
3333
left_motor_value = int(left_motor * 65535)
3434
else:
@@ -43,7 +43,7 @@ def set_vibration(left_motor, right_motor, controller=0):
4343
XInputSetState(controller, ctypes.byref(vibration))
4444

4545

46-
def set_vibration_with_duration(left_motor, right_motor, controller=0, duration=1.0):
46+
def set_vibration_with_duration(left_motor, right_motor, controller=0, duration=1.0) -> None:
4747
t = time.time()
4848

4949
while True:

‎rumble (vibration) a xbox 360 controller/web/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def get_status():
210210
return jsonify(data)
211211

212212

213-
def vibration_tick():
213+
def vibration_tick() -> None:
214214
while True:
215215
if DEBUG:
216216
print(

‎run_processes_with_output_in_web/common.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class Task:
3737
process_return_code: int = None
3838
__need_stop: bool = field(init=False, repr=False, default=False)
3939

40-
def run(self, threaded: bool = False):
40+
def run(self, threaded: bool = False) -> None:
4141
self.status = TaskStatusEnum.Running
4242

43-
def process_callback(process: Popen):
43+
def process_callback(process: Popen) -> None:
4444
self.process = process
4545
self.process_id = self.process.pid
4646

47-
def on_exit():
47+
def on_exit() -> None:
4848
self.status = TaskStatusEnum.Stopped if self.__need_stop else TaskStatusEnum.Finished
4949
self.process_return_code = self.process.returncode
5050

@@ -64,16 +64,16 @@ def stop_on() -> bool:
6464
stop_on=stop_on,
6565
)
6666

67-
def stop(self):
67+
def stop(self) -> None:
6868
self.__need_stop = True
6969

7070

7171
if __name__ == "__main__":
7272

73-
def process_stdout(text):
73+
def process_stdout(text) -> None:
7474
print("process_stdout:", repr(text))
7575

76-
def process_stderr(text):
76+
def process_stderr(text) -> None:
7777
print("process_stderr:", repr(text))
7878

7979
task = Task(

‎run_processes_with_output_in_web/main.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def index():
4747

4848

4949
@socketio.on("run")
50-
def run(message):
51-
def send_update_task(stdout: str = None, stderr: str = None):
50+
def run(message) -> None:
51+
def send_update_task(stdout: str = None, stderr: str = None) -> None:
5252
data = dict(
5353
id=task.id,
5454
command=task.command,
@@ -61,10 +61,10 @@ def send_update_task(stdout: str = None, stderr: str = None):
6161
print("send_update_task", data)
6262
emit("update_task", data)
6363

64-
def process_stdout(text: str):
64+
def process_stdout(text: str) -> None:
6565
send_update_task(stdout=text)
6666

67-
def process_stderr(text: str):
67+
def process_stderr(text: str) -> None:
6868
send_update_task(stderr=text)
6969

7070
task = Task(

‎scapy__examples/sniff__gui__pyqt5/main.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from scapy.all import sniff
1616

1717

18-
def log_uncaught_exceptions(ex_cls, ex, tb):
18+
def log_uncaught_exceptions(ex_cls, ex, tb) -> None:
1919
text = f"{ex_cls.__name__}: {ex}:\n"
2020
text += "".join(traceback.format_tb(tb))
2121

@@ -30,18 +30,18 @@ def log_uncaught_exceptions(ex_cls, ex, tb):
3030
class SniffThread(Qt.QThread):
3131
about_new_data = Qt.pyqtSignal(str)
3232

33-
def _packethandler(self, pkt):
33+
def _packethandler(self, pkt) -> None:
3434
data = pkt.summary()
3535
print(data)
3636

3737
self.about_new_data.emit(data)
3838

39-
def run(self):
39+
def run(self) -> None:
4040
sniff(filter="tcp", prn=self._packethandler)
4141

4242

4343
class MainWindow(Qt.QMainWindow):
44-
def __init__(self):
44+
def __init__(self) -> None:
4545
super().__init__()
4646

4747
self.setWindowTitle("Sniff with scapy")
@@ -74,7 +74,7 @@ def __init__(self):
7474
self.thread.about_new_data.connect(self._append_new_item)
7575
self.thread.start()
7676

77-
def _append_new_item(self, data):
77+
def _append_new_item(self, data) -> None:
7878
# Если флаг не стоит
7979
if not self.cb_log.isChecked():
8080
return

0 commit comments

Comments
 (0)