Browse Source

Fix Mypy errors

Maarten van den Berg 5 years ago
parent
commit
b220ea7c32
1 changed files with 20 additions and 10 deletions
  1. 20 10
      piket_client/gui.py

+ 20 - 10
piket_client/gui.py

3
 """
3
 """
4
 import collections
4
 import collections
5
 import logging
5
 import logging
6
+import math
6
 import os
7
 import os
7
 import sys
8
 import sys
9
+from typing import Deque
8
 
10
 
9
 import qdarkstyle
11
 import qdarkstyle
10
 
12
 
78
     @Slot()
80
     @Slot()
79
     def rebuild(self) -> None:
81
     def rebuild(self) -> None:
80
         """ Refresh the Person object and the label. """
82
         """ Refresh the Person object and the label. """
81
-        self.person = self.person.reload()
83
+        self.person = self.person.reload()  # type: ignore
82
         self.setText(self.current_label)
84
         self.setText(self.current_label)
83
 
85
 
84
     @property
86
     @property
149
         LOG.debug("Initializing NameButtons.")
151
         LOG.debug("Initializing NameButtons.")
150
 
152
 
151
         ps = Person.get_all(True)
153
         ps = Person.get_all(True)
152
-        num_columns = round(len(ps) / 10) + 1
154
+        assert not isinstance(ps, NetworkError)
155
+        num_columns = math.ceil(math.sqrt(len(ps)))
153
 
156
 
154
         if self.layout:
157
         if self.layout:
155
             LOG.debug("Removing %s widgets for rebuild", self.layout.count())
158
             LOG.debug("Removing %s widgets for rebuild", self.layout.count())
183
         self.toolbar = None
186
         self.toolbar = None
184
         self.osk = None
187
         self.osk = None
185
         self.undo_action = None
188
         self.undo_action = None
186
-        self.undo_queue = collections.deque([], 15)
189
+        self.undo_queue: Deque[Consumption] = collections.deque([], 15)
187
         self.init_ui()
190
         self.init_ui()
188
 
191
 
189
     def init_ui(self) -> None:
192
     def init_ui(self) -> None:
212
 
215
 
213
         # Initialize toolbar
216
         # Initialize toolbar
214
         self.toolbar = QToolBar()
217
         self.toolbar = QToolBar()
218
+        assert self.toolbar is not None
215
         self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
219
         self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
216
         self.toolbar.setIconSize(QSize(icon_size, icon_size))
220
         self.toolbar.setIconSize(QSize(icon_size, icon_size))
217
 
221
 
239
         self.toolbar.setContextMenuPolicy(Qt.PreventContextMenu)
243
         self.toolbar.setContextMenuPolicy(Qt.PreventContextMenu)
240
         self.toolbar.setFloatable(False)
244
         self.toolbar.setFloatable(False)
241
         self.toolbar.setMovable(False)
245
         self.toolbar.setMovable(False)
242
-        self.ct_ag = QActionGroup(self.toolbar)
246
+        self.ct_ag: QActionGroup = QActionGroup(self.toolbar)
243
         self.ct_ag.setExclusive(True)
247
         self.ct_ag.setExclusive(True)
244
 
248
 
245
         cts = ConsumptionType.get_all()
249
         cts = ConsumptionType.get_all()
311
         """ Ask for a new Person and register it, then rebuild the central
315
         """ Ask for a new Person and register it, then rebuild the central
312
         widget. """
316
         widget. """
313
         inactive_persons = Person.get_all(False)
317
         inactive_persons = Person.get_all(False)
318
+        assert not isinstance(inactive_persons, NetworkError)
319
+
314
         inactive_persons.sort(key=lambda p: p.name)
320
         inactive_persons.sort(key=lambda p: p.name)
315
         inactive_names = [p.name for p in inactive_persons]
321
         inactive_names = [p.name for p in inactive_persons]
316
 
322
 
331
                 person.set_active(True)
337
                 person.set_active(True)
332
 
338
 
333
             else:
339
             else:
334
-                person = Person(name=name)
335
-                person = person.create()
340
+                person = Person(full_name=name, display_name=None, )
341
+                person.create()
336
 
342
 
343
+            assert self.main_widget is not None
337
             self.main_widget.init_ui()
344
             self.main_widget.init_ui()
338
 
345
 
339
     def add_consumption_type(self) -> None:
346
     def add_consumption_type(self) -> None:
344
         self.hide_keyboard()
351
         self.hide_keyboard()
345
 
352
 
346
         if ok and name:
353
         if ok and name:
347
-            ct = ConsumptionType(name=name)
348
-            ct = ct.create()
354
+            ct = ConsumptionType(name=name).create()
355
+            assert not isinstance(ct, NetworkError)
349
 
356
 
350
             action = QAction(
357
             action = QAction(
351
                 self.load_icon(ct.icon or "beer_bottle.svg"), ct.name, self.ct_ag
358
                 self.load_icon(ct.icon or "beer_bottle.svg"), ct.name, self.ct_ag
353
             action.setCheckable(True)
360
             action.setCheckable(True)
354
             action.setData(str(ct.consumption_type_id))
361
             action.setData(str(ct.consumption_type_id))
355
 
362
 
363
+            assert self.toolbar is not None
356
             self.toolbar.addAction(action)
364
             self.toolbar.addAction(action)
357
 
365
 
358
     def confirm_quit(self) -> None:
366
     def confirm_quit(self) -> None:
383
             self.undo_queue.append(to_undo)
391
             self.undo_queue.append(to_undo)
384
 
392
 
385
         elif not self.undo_queue:
393
         elif not self.undo_queue:
394
+            assert self.undo_action is not None
386
             self.undo_action.setDisabled(True)
395
             self.undo_action.setDisabled(True)
387
 
396
 
397
+        assert self.main_widget is not None
388
         self.main_widget.init_ui()
398
         self.main_widget.init_ui()
389
 
399
 
390
     @Slot(Consumption)
400
     @Slot(Consumption)
480
                     f'{item["count"]} {item["name"]}'
490
                     f'{item["count"]} {item["name"]}'
481
                     for item in settlement.consumption_summary.values()
491
                     for item in settlement.consumption_summary.values()
482
                 ]
492
                 ]
483
-                info = ", ".join(info)
493
+                info2 = ", ".join(info)
484
                 QMessageBox.information(
494
                 QMessageBox.information(
485
-                    None, "Lijst afgesloten", f"VO! Op deze lijst stonden: {info}"
495
+                    None, "Lijst afgesloten", f"VO! Op deze lijst stonden: {info2}"
486
                 )
496
                 )
487
 
497
 
488
                 main_window = PiketMainWindow()
498
                 main_window = PiketMainWindow()