Skip to content

Commit a145b48

Browse files
committed
Refactoring. Adding the None annotation to the return value
1 parent 1d5d12c commit a145b48

27 files changed

Lines changed: 47 additions & 47 deletions

File tree

‎Printing all instances of a class/use__garbage_collector__gc.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_instances(class_: type) -> [type]:
1515

1616

1717
class X:
18-
def __init__(self, name):
18+
def __init__(self, name) -> None:
1919
self.name = name
2020

2121

‎Printing all instances of a class/use__mixin_and_weakrefs.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class KeepRefs:
1515
__refs__ = defaultdict(list)
1616

17-
def __init__(self):
17+
def __init__(self) -> None:
1818
self.__refs__[self.__class__].append(weakref.ref(self))
1919

2020
@classmethod
@@ -26,7 +26,7 @@ def get_instances(cls):
2626

2727

2828
class X(KeepRefs):
29-
def __init__(self, name):
29+
def __init__(self, name) -> None:
3030
super().__init__()
3131
self.name = name
3232

‎pretty_xml/pretty_xml_gui.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from pretty_xml import pretty_xml_lxml as to_pretty_xml
2929

3030

31-
def log_uncaught_exceptions(ex_cls, ex, tb):
31+
def log_uncaught_exceptions(ex_cls, ex, tb) -> None:
3232
text = f"{ex_cls.__name__}: {ex}:\n"
3333
text += "".join(traceback.format_tb(tb))
3434

@@ -41,7 +41,7 @@ def log_uncaught_exceptions(ex_cls, ex, tb):
4141

4242

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

4747
self.setWindowTitle(Path(__file__).name)
@@ -80,7 +80,7 @@ def __init__(self):
8080

8181
layout.addLayout(layout_error)
8282

83-
def input_text_changed(self):
83+
def input_text_changed(self) -> None:
8484
self.label_error.clear()
8585
self.button_detail_error.hide()
8686

@@ -105,7 +105,7 @@ def input_text_changed(self):
105105

106106
self.label_error.setText("Error: " + self.last_error_message)
107107

108-
def show_detail_error_message(self):
108+
def show_detail_error_message(self) -> None:
109109
message = self.last_error_message + "\n\n" + self.last_detail_error_message
110110

111111
mb = QErrorMessage()

‎proxy.py__examples/ca_certificate.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from config import CA_KEY_FILE_PATH, CA_CERT_FILE_PATH, CA_SIGNING_KEY_FILE_PATH
1212

1313

14-
def main():
14+
def main() -> None:
1515
# Generate CA key
1616
os.system(
1717
f"python -m proxy.common.pki gen_private_key --private-key-path {CA_KEY_FILE_PATH}"

‎proxy.py__examples/hello_world.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def on_upstream_connection_close(self) -> None:
3636
pass
3737

3838

39-
def main(*args, **kwargs):
39+
def main(*args, **kwargs) -> None:
4040
proxy.main(
4141
*args,
4242
hostname=ipaddress.ip_address("127.0.0.1"),

‎psutil_example/disc_used_DIFF/common.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_disc_total_used(disc_list: List[str]) -> str:
5858
return sizeof_fmt(sum(psutil.disk_usage(disk).used for disk in disc_list))
5959

6060

61-
def write_snapshot_raw_disc_used(disc_list: List[str] = None):
61+
def write_snapshot_raw_disc_used(disc_list: List[str] = None) -> None:
6262
with open(FILE_NAME_SNAPSHOT, "w", encoding="utf-8") as f:
6363
items = get_disc_used(disc_list, only_raw=True)
6464
print("Write snapshot with:", items)

‎psutil_example/on_new_process_handler.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717

1818
class OnNewProcessHandler(Thread):
19-
def __init__(self, timeout_secs=1.0):
19+
def __init__(self, timeout_secs=1.0) -> None:
2020
super().__init__()
2121

2222
self._process = dict()
2323
self._listeners: list[ListenerFunc] = []
2424
self._timeout_secs = timeout_secs
2525

26-
def add_listener(self, listener: ListenerFunc):
26+
def add_listener(self, listener: ListenerFunc) -> None:
2727
if listener not in self._listeners:
2828
self._listeners.append(listener)
2929

30-
def remove_listener(self, listener: ListenerFunc):
30+
def remove_listener(self, listener: ListenerFunc) -> None:
3131
if listener in self._listeners:
3232
self._listeners.remove(listener)
3333

34-
def remove_all_listener(self):
34+
def remove_all_listener(self) -> None:
3535
self._listeners.clear()
3636

3737
@staticmethod
@@ -48,7 +48,7 @@ def get_process() -> dict:
4848

4949
return items
5050

51-
def run(self):
51+
def run(self) -> None:
5252
while True:
5353
current_process = self.get_process()
5454

@@ -71,7 +71,7 @@ def run(self):
7171

7272
if __name__ == "__main__":
7373

74-
def print_listener(process_list):
74+
def print_listener(process_list) -> None:
7575
result = []
7676
for p in process_list:
7777
result.append(f"{p['name']} (pid={p['pid']})")

‎psutil_example/print_all_webservers/get_info_html.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get_info_html() -> str:
147147
)
148148

149149

150-
def open_html_file():
150+
def open_html_file() -> None:
151151
with tempfile.NamedTemporaryFile(
152152
mode="w",
153153
encoding="utf-8",

‎psutil_example/print_all_webservers/web.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class HttpProcessor(BaseHTTPRequestHandler):
16-
def do_GET(self):
16+
def do_GET(self) -> None:
1717
o = urlsplit(self.path)
1818

1919
# Only index
@@ -31,7 +31,7 @@ def do_GET(self):
3131
self.wfile.write(text.encode("utf-8"))
3232

3333

34-
def run(server_class=HTTPServer, handler_class=HttpProcessor, port=8080):
34+
def run(server_class=HTTPServer, handler_class=HttpProcessor, port=8080) -> None:
3535
print(f"HTTP server running on http://127.0.0.1:{port}")
3636

3737
server_address = ("", port)

‎psutil_example/print_current_python_webservers/web.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _get_processes() -> list[dict[str, str | int]]:
5050

5151

5252
class HttpProcessor(BaseHTTPRequestHandler):
53-
def do_GET(self):
53+
def do_GET(self) -> None:
5454
o = urlsplit(self.path)
5555

5656
# Only index
@@ -131,7 +131,7 @@ def do_GET(self):
131131
self.wfile.write(text.encode("utf-8"))
132132

133133

134-
def run(server_class=HTTPServer, handler_class=HttpProcessor, port=8080):
134+
def run(server_class=HTTPServer, handler_class=HttpProcessor, port=8080) -> None:
135135
print(f"HTTP server running on http://127.0.0.1:{port}")
136136

137137
server_address = ("", port)

0 commit comments

Comments
 (0)