Skip to content

Commit e7e68a1

Browse files
committed
Refactoring. job_compassplus/. Adding the None annotation to the return value
1 parent 605eec8 commit e7e68a1

21 files changed

Lines changed: 67 additions & 67 deletions

File tree

‎job_compassplus/current_job_report/main.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def draw_text_to_bottom_right(
6464

6565

6666
# Для отлова всех исключений, которые в слотах Qt могут "затеряться" и привести к тихому падению
67-
def log_uncaught_exceptions(ex_cls, ex, tb):
67+
def log_uncaught_exceptions(ex_cls, ex, tb) -> None:
6868
text = f"{ex_cls.__name__}: {ex}:\n"
6969
text += "".join(traceback.format_tb(tb))
7070

@@ -85,13 +85,13 @@ class CheckJobReportThread(QThread):
8585
about_ok = pyqtSignal(bool)
8686
about_log = pyqtSignal(str)
8787

88-
def __init__(self):
88+
def __init__(self) -> None:
8989
super().__init__()
9090

9191
self.last_text = None
9292
self.ok = None
9393

94-
def do_run(self):
94+
def do_run(self) -> None:
9595
def _get_title(deviation_hours):
9696
ok = deviation_hours[0] != "-"
9797
return "Переработка" if ok else "Недоработка"
@@ -134,7 +134,7 @@ def _get_title(deviation_hours):
134134
self.ok = ok
135135
self.about_ok.emit(self.ok)
136136

137-
def run(self):
137+
def run(self) -> None:
138138
while True:
139139
try:
140140
# Между 08:00 и 20:00
@@ -150,7 +150,7 @@ def run(self):
150150

151151

152152
class JobReportWidget(QWidget):
153-
def __init__(self):
153+
def __init__(self) -> None:
154154
super().__init__()
155155

156156
self.info = QLabel()
@@ -212,23 +212,23 @@ def __init__(self):
212212

213213
button_refresh.clicked.connect(self.refresh)
214214

215-
def set_text(self, text: str):
215+
def set_text(self, text: str) -> None:
216216
print(text)
217217
self.info.setText(text)
218218

219-
def refresh(self):
219+
def refresh(self) -> None:
220220
# Выполнение метода в отдельном потоке, а не в GUI
221221
Thread(target=self.thread.do_run, daemon=True).start()
222222

223-
def _set_ok(self, val: bool):
223+
def _set_ok(self, val: bool) -> None:
224224
self.ok = val
225225
self.update()
226226

227-
def _add_log(self, val: str):
227+
def _add_log(self, val: str) -> None:
228228
print(val)
229229
self.log.appendPlainText(val)
230230

231-
def paintEvent(self, event):
231+
def paintEvent(self, event) -> None:
232232
super().paintEvent(event)
233233

234234
if self.ok is None:
@@ -248,7 +248,7 @@ def paintEvent(self, event):
248248

249249
tray = QSystemTrayIcon(QIcon(TRAY_ICON))
250250

251-
def _on_about_log_or_ok(value: str | bool):
251+
def _on_about_log_or_ok(value: str | bool) -> None:
252252
if isinstance(value, str):
253253
text = "🔄"
254254
else:

‎job_compassplus/mysite_compassplus_com/get_profile_info_from_web/db.py‎

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

3232

3333
class NotDefinedParameterException(ValueError):
34-
def __init__(self, parameter_name: str):
34+
def __init__(self, parameter_name: str) -> None:
3535
self.parameter_name = parameter_name
3636
text = f'Parameter "{self.parameter_name}" must be defined!'
3737

@@ -63,7 +63,7 @@ def get_inherited_models(cls) -> list[Type["BaseModel"]]:
6363
return sorted(cls.__subclasses__(), key=lambda x: x.__name__)
6464

6565
@classmethod
66-
def print_count_of_tables(cls):
66+
def print_count_of_tables(cls) -> None:
6767
items = []
6868
for sub_cls in cls.get_inherited_models():
6969
name = sub_cls.__name__
@@ -82,7 +82,7 @@ def count(cls, filters: Iterable = None) -> int:
8282
def to_dict(self) -> dict[str, Any]:
8383
return model_to_dict(self, recurse=False)
8484

85-
def __str__(self):
85+
def __str__(self) -> str:
8686
fields = []
8787
for k, field in self._meta.fields.items():
8888
v = getattr(self, k)

‎job_compassplus/mysite_compassplus_com/get_profile_info_from_web/db_backup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def backup(
5252
return file_name
5353

5454

55-
def do_backup_db():
55+
def do_backup_db() -> None:
5656
prefix: str = "[do_backup_db]"
5757

5858
print(f"{prefix} Start")

‎job_compassplus/mysite_compassplus_com/get_profile_info_from_web/db_updater.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def add_or_get_db(name: str, forced: bool = False) -> db.Person | None:
9898
return person
9999

100100

101-
def do_update_db(forced: bool = False):
101+
def do_update_db(forced: bool = False) -> None:
102102
prefix: str = "[do_update_db]"
103103

104104
print(f"{prefix} Start")

‎job_compassplus/parse_jira_Assigned_Open_Issues_per_Project/common.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_table(assigned_open_issues_per_project: dict[str, int]) -> str:
2525
)
2626

2727

28-
def print_table(assigned_open_issues_per_project: dict[str, int]):
28+
def print_table(assigned_open_issues_per_project: dict[str, int]) -> None:
2929
print(get_table(assigned_open_issues_per_project))
3030
# PROJECT | Issues
3131
# --------+-------

‎job_compassplus/parse_jira_Assigned_Open_Issues_per_Project/db.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
DB_FILE_NAME = str(DIR / "database.sqlite")
3131

3232

33-
def db_create_backup(backup_dir=DIR / "backup"):
33+
def db_create_backup(backup_dir=DIR / "backup") -> None:
3434
os.makedirs(backup_dir, exist_ok=True)
3535

3636
file_name = str(dt.datetime.today().date()) + ".sqlite"
@@ -47,7 +47,7 @@ class BaseModel(Model):
4747
class Meta:
4848
database = db
4949

50-
def __str__(self):
50+
def __str__(self) -> str:
5151
fields = []
5252
for k, field in self._meta.fields.items():
5353
v = getattr(self, k)
@@ -75,7 +75,7 @@ def get_total_issues(self) -> int:
7575
def get_project_by_issue_numbers(self) -> dict[str, int]:
7676
return {issue.project.name: issue.value for issue in self.issue_numbers}
7777

78-
def __str__(self):
78+
def __str__(self) -> str:
7979
return f"{self.__class__.__name__}(id={self.id}, date={self.date}, total_issues={self.get_total_issues()})"
8080

8181

‎job_compassplus/parse_jira_Assigned_Open_Issues_per_Project/gui.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from chart_line__show_tooltip_on_series__QtChart import ChartViewToolTips
4444

4545

46-
def log_uncaught_exceptions(ex_cls, ex, tb):
46+
def log_uncaught_exceptions(ex_cls, ex, tb) -> None:
4747
text = f"{ex_cls.__name__}: {ex}:\n"
4848
text += "".join(traceback.format_tb(tb))
4949

@@ -95,7 +95,7 @@ class GetAssignedOpenIssuesPerProjectThread(QThread):
9595
about_items = pyqtSignal(dict)
9696
about_error = pyqtSignal(Exception)
9797

98-
def run(self):
98+
def run(self) -> None:
9999
try:
100100
items: dict[str, int] = get_assigned_open_issues_per_project()
101101
self.about_items.emit(items)
@@ -108,7 +108,7 @@ def run(self):
108108

109109

110110
class TableWidgetRun(QWidget):
111-
def __init__(self):
111+
def __init__(self) -> None:
112112
super().__init__()
113113

114114
self.table_run = get_table_widget(["DATE", "TOTAL ISSUES"])
@@ -129,7 +129,7 @@ def __init__(self):
129129

130130
self.setLayout(main_layout)
131131

132-
def refresh(self, items: list[Run]):
132+
def refresh(self, items: list[Run]) -> None:
133133
# Удаление строк таблицы
134134
while self.table_run.rowCount():
135135
self.table_run.removeRow(0)
@@ -148,7 +148,7 @@ def refresh(self, items: list[Run]):
148148
self.table_run.setFocus()
149149
self._on_table_run_item_clicked()
150150

151-
def _on_table_run_item_clicked(self):
151+
def _on_table_run_item_clicked(self) -> None:
152152
# Удаление строк таблицы
153153
while self.table_issues.rowCount():
154154
self.table_issues.removeRow(0)
@@ -165,7 +165,7 @@ def _on_table_run_item_clicked(self):
165165

166166

167167
class CurrentAssignedOpenIssues(QWidget):
168-
def __init__(self):
168+
def __init__(self) -> None:
169169
super().__init__()
170170

171171
self.table = get_table_widget(["PROJECT", "NUMBER"])
@@ -208,10 +208,10 @@ def __init__(self):
208208
self.current_items: dict[str, int] | None = None
209209
self._update_total_issues("-")
210210

211-
def _update_total_issues(self, value):
211+
def _update_total_issues(self, value) -> None:
212212
self.label_total.setText(f"<b>Total issues:</b> {value}")
213213

214-
def _on_set_items(self, items: dict[str, int]):
214+
def _on_set_items(self, items: dict[str, int]) -> None:
215215
self.current_items = items
216216

217217
self._update_total_issues(sum(self.current_items.values()))
@@ -230,25 +230,25 @@ def _on_set_items(self, items: dict[str, int]):
230230
f"Last refresh date: {get_human_datetime()}"
231231
)
232232

233-
def _on_error(self, e: Exception):
233+
def _on_error(self, e: Exception) -> None:
234234
tb_str = "".join(traceback.format_tb(e.__traceback__))
235235
print(tb_str)
236236
QMessageBox.warning(self, "ERROR", str(e))
237237

238-
def refresh(self):
238+
def refresh(self) -> None:
239239
self.current_items = None
240240

241241
self.thread.start()
242242

243243

244244
class MyChartViewToolTips(ChartViewToolTips):
245-
def __init__(self, timestamp_by_info: dict[int, dict[str, int]]):
245+
def __init__(self, timestamp_by_info: dict[int, dict[str, int]]) -> None:
246246
super().__init__()
247247

248248
self._callout_font_family = "Courier"
249249
self.timestamp_by_info: dict[int, dict[str, int]] = timestamp_by_info
250250

251-
def show_series_tooltip(self, point, state: bool):
251+
def show_series_tooltip(self, point, state: bool) -> None:
252252
# value -> pos
253253
point = self.chart().mapToPosition(point)
254254

@@ -290,7 +290,7 @@ def show_series_tooltip(self, point, state: bool):
290290

291291

292292
class MainWindow(QMainWindow):
293-
def __init__(self):
293+
def __init__(self) -> None:
294294
super().__init__()
295295

296296
self.setWindowTitle(WINDOW_TITLE)
@@ -358,7 +358,7 @@ def _get_datetime(self, date: date, delta: timedelta = None) -> datetime:
358358
dt += delta
359359
return dt
360360

361-
def _fill_chart_filter(self, items: list[Run]):
361+
def _fill_chart_filter(self, items: list[Run]) -> None:
362362
years: list[int] = sorted({run.date.year for run in items})
363363
filter_years: list[int] = [
364364
self.cb_chart_filter.itemData(i)
@@ -368,7 +368,7 @@ def _fill_chart_filter(self, items: list[Run]):
368368
if year not in filter_years:
369369
self.cb_chart_filter.addItem(f"{year}", userData=year)
370370

371-
def _fill_chart(self, items: list[Run]):
371+
def _fill_chart(self, items: list[Run]) -> None:
372372
# Фильтрация данных из графика
373373
year: int = self.cb_chart_filter.currentData()
374374
if year:
@@ -433,7 +433,7 @@ def _fill_chart(self, items: list[Run]):
433433
self.chart_view.clear_all_tooltips()
434434
self.chart_view.setChart(chart)
435435

436-
def refresh(self):
436+
def refresh(self) -> None:
437437
self.current_assigned_open_issues.refresh()
438438

439439
items = list(Run.select())
@@ -449,7 +449,7 @@ def refresh(self):
449449
f"{WINDOW_TITLE}. Last refresh date: {get_human_datetime()}"
450450
)
451451

452-
def _on_tray_activated(self, reason: QSystemTrayIcon.ActivationReason):
452+
def _on_tray_activated(self, reason: QSystemTrayIcon.ActivationReason) -> None:
453453
# Если запрошено меню
454454
if reason == QSystemTrayIcon.Context:
455455
return
@@ -460,14 +460,14 @@ def _on_tray_activated(self, reason: QSystemTrayIcon.ActivationReason):
460460
self.showNormal()
461461
self.activateWindow()
462462

463-
def changeEvent(self, event: QEvent):
463+
def changeEvent(self, event: QEvent) -> None:
464464
if event.type() == QEvent.WindowStateChange:
465465
# Если окно свернули
466466
if self.isMinimized():
467467
# Прячем окно с панели задач
468468
QTimer.singleShot(0, self.hide)
469469

470-
def closeEvent(self, event: QCloseEvent):
470+
def closeEvent(self, event: QCloseEvent) -> None:
471471
self.hide()
472472
event.ignore()
473473

‎job_compassplus/portal_compassplus_com/employees_gui/db.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ def parse(xml, session):
134134

135135
return employee
136136

137-
def __str__(self):
137+
def __str__(self) -> str:
138138
return f'<Employee("{self.name}" ({self.short_name}), job: {self.job}, department: {self.department})>'
139139

140-
def __repr__(self):
140+
def __repr__(self) -> str:
141141
return self.__str__()
142142

143143

@@ -162,7 +162,7 @@ def get_session():
162162
db_session = get_session()
163163

164164

165-
def exists(employee_id):
165+
def exists(employee_id) -> bool:
166166
return (
167167
db_session.query(Employee).filter(Employee.id == employee_id).scalar()
168168
is not None

0 commit comments

Comments
 (0)