Skip to content

Commit 7b738a4

Browse files
elParaguayofdev31
authored andcommitted
Fix CI: mypy
Removed mypy from testenv - No benefit of running mypy tests in every environment - py39 has `mypy` environment which runs `test_check` and `test_migrate` so tests will be run. Added missing dependencies for tox mypy tests: - dbus-next - PyGObject (needed for dbus-next's glib interface which we don't use...) Fixed failures in codebase: - sh.py: qtile#2936 fixed a bug but moved an import into an `import_module` call. As per python/mypy#5059 mypy can't follow this so we need to add `# type: ignore` to the impacted lines. - run_cmd.py: duplicate variable name fixed. - battery.py: `background` and `low_background` need types because of additional logic in widget. - scripts/main.py: silence mypy on `distribution` import as will fail for python 3.7 - various wayland files: missing imports, adding assertions to help identity optional type, correcting types
1 parent e5aeb8d commit 7b738a4

10 files changed

Lines changed: 44 additions & 36 deletions

File tree

‎libqtile/backend/wayland/core.py‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
from libqtile.log_utils import logger
8080

8181
if typing.TYPE_CHECKING:
82-
from typing import List, Optional, Sequence, Tuple, Union
82+
from typing import List, Optional, Sequence, Set, Tuple, Union
8383

8484
from wlroots.wlr_types import Output as wlrOutput
8585
from wlroots.wlr_types.data_device_manager import Drag
@@ -457,7 +457,10 @@ def _output_manager_reconfigure(
457457
hook.fire("screens_reconfigured")
458458

459459
def _process_cursor_motion(self, time_msec: int, cx: float, cy: float):
460-
self.qtile.process_button_motion(int(cx), int(cy))
460+
assert self.qtile
461+
cx_int = int(cx)
462+
cy_int = int(cy)
463+
self.qtile.process_button_motion(cx_int, cy_int)
461464

462465
if len(self.outputs) > 1:
463466
current_output = self.output_layout.output_at(cx, cy).data
@@ -475,18 +478,18 @@ def _process_cursor_motion(self, time_msec: int, cx: float, cy: float):
475478
if isinstance(win, window.Internal):
476479
if self._hovered_internal is win:
477480
win.process_pointer_motion(
478-
cx - self._hovered_internal.x,
479-
cy - self._hovered_internal.y,
481+
cx_int - self._hovered_internal.x,
482+
cy_int - self._hovered_internal.y,
480483
)
481484
else:
482485
if self._hovered_internal:
483486
self._hovered_internal.process_pointer_leave(
484-
cx - self._hovered_internal.x,
485-
cy - self._hovered_internal.y,
487+
cx_int - self._hovered_internal.x,
488+
cy_int - self._hovered_internal.y,
486489
)
487490
self.cursor_manager.set_cursor_image("left_ptr", self.cursor)
488491
self.seat.pointer_notify_clear_focus()
489-
win.process_pointer_enter(cx, cy)
492+
win.process_pointer_enter(cx_int, cy_int)
490493
self._hovered_internal = win
491494
return
492495

@@ -520,8 +523,8 @@ def _process_cursor_motion(self, time_msec: int, cx: float, cy: float):
520523
self.seat.pointer_notify_clear_focus()
521524
if self._hovered_internal:
522525
self._hovered_internal.process_pointer_leave(
523-
cx - self._hovered_internal.x,
524-
cy - self._hovered_internal.y,
526+
cx_int - self._hovered_internal.x,
527+
cy_int - self._hovered_internal.y,
525528
)
526529
self._hovered_internal = None
527530

@@ -594,6 +597,7 @@ def distribute_windows(self, initial: bool) -> None:
594597
continue
595598

596599
group = None
600+
assert isinstance(win, window.Window)
597601
if win.group:
598602
if win.group.name in self.qtile.groups_map:
599603
# Put window on group with same name as its old group if one exists

‎libqtile/backend/wayland/keyboard.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, core: Core, device: InputDevice):
5555

5656
self.keyboard.set_repeat_info(25, 600)
5757
self.xkb_context = xkb.Context()
58-
self._keymaps: Dict[Tuple[Optional[str], Optional[str]], xkb.Keymap] = {}
58+
self._keymaps: Dict[Tuple[Optional[str], ...], xkb.Keymap] = {}
5959
self.set_keymap(None, None, None)
6060

6161
self.add_listener(self.keyboard.modifiers_event, self._on_modifier)

‎libqtile/backend/wayland/output.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from libqtile.log_utils import logger
4141

4242
if typing.TYPE_CHECKING:
43-
from typing import List, Tuple
43+
from typing import List, Tuple, Union
4444

4545
from wlroots.wlr_types import Surface
4646

@@ -220,6 +220,7 @@ def _render_surface(self, surface: Surface, sx: int, sy: int, rdata: Tuple) -> N
220220
def _render_dnd_icon(self, now: Timespec) -> None:
221221
"""Render the drag-n-drop icon if there is one."""
222222
dnd = self.core.live_dnd
223+
assert dnd
223224
icon = dnd.wlr_drag.icon
224225
if icon.mapped:
225226
texture = icon.surface.get_texture()

‎libqtile/backend/wayland/wlrq.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from libqtile.utils import QtileError
4040

4141
if TYPE_CHECKING:
42-
from typing import Callable, List, Optional
42+
from typing import Callable, List, Optional, Set
4343

4444
from pywayland.server import Signal
4545
from wlroots.wlr_types import Box, data_device_manager

‎libqtile/scripts/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
try:
99
# Python>3.7 can get the version from importlib
10-
from importlib.metadata import distribution
10+
from importlib.metadata import distribution # type: ignore
1111
VERSION = distribution("qtile").version
1212
except ModuleNotFoundError:
1313
try:

‎libqtile/scripts/run_cmd.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def run_cmd(opts) -> None:
4747
rule_args = {"float": opts.float, "intrusive": opts.intrusive,
4848
"group": opts.group, "break_on_match": not opts.dont_break}
4949

50-
cmd = root.call("add_rule")
51-
_, rule_id = client.send((root.selectors, cmd.name, (match_args, rule_args), {}))
50+
graph_cmd = root.call("add_rule")
51+
_, rule_id = client.send((root.selectors, graph_cmd.name, (match_args, rule_args), {}))
5252

5353
def remove_rule() -> None:
5454
cmd = root.call("remove_rule")

‎libqtile/sh.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self, client: CommandInterface, completekey="tab") -> None:
6363
self._builtins = [i[3:] for i in dir(self) if i.startswith("do_")]
6464

6565
def complete(self, arg, state) -> Optional[str]:
66-
buf = self.readline.get_line_buffer()
66+
buf = self.readline.get_line_buffer() # type: ignore
6767
completers = self._complete(buf, arg)
6868
if completers and state < len(completers):
6969
return completers[state]
@@ -335,9 +335,9 @@ def process_line(self, line: str) -> Any:
335335
return "Invalid command: {}".format(line)
336336

337337
def loop(self) -> None:
338-
self.readline.set_completer(self.complete)
339-
self.readline.parse_and_bind(self._completekey + ": complete")
340-
self.readline.set_completer_delims(" ()|")
338+
self.readline.set_completer(self.complete) # type: ignore
339+
self.readline.parse_and_bind(self._completekey + ": complete") # type: ignore
340+
self.readline.set_completer_delims(" ()|") # type: ignore
341341

342342
while True:
343343
try:

‎libqtile/widget/battery.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from libqtile import bar, configurable, images
4343
from libqtile.images import Img
4444
from libqtile.log_utils import logger
45-
from libqtile.utils import send_notification
45+
from libqtile.utils import ColorsType, send_notification
4646
from libqtile.widget import base
4747

4848

@@ -306,6 +306,8 @@ def update_status(self) -> BatteryStatus:
306306

307307
class Battery(base.ThreadPoolText):
308308
"""A text-based battery monitoring widget currently supporting FreeBSD"""
309+
background: Optional[ColorsType]
310+
low_background: Optional[ColorsType]
309311
orientations = base.ORIENTATION_HORIZONTAL
310312
defaults = [
311313
('charge_char', '^', 'Character to indicate the battery is charging'),

‎libqtile/widget/statusnotifier.py‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,13 @@ class StatusNotifierWatcher(ServiceInterface): # noqa: E303
345345
"""
346346
def __init__(self, service: str):
347347
super().__init__(service)
348-
self._items = []
349-
self._hosts = []
348+
self._items: List[str] = []
349+
self._hosts: List[str] = []
350350
self.service = service
351-
self.on_item_added = None
352-
self.on_host_added = None
353-
self.on_item_removed = None
354-
self.on_host_removed = None
351+
self.on_item_added: Optional[Callable] = None
352+
self.on_host_added: Optional[Callable] = None
353+
self.on_item_removed: Optional[Callable] = None
354+
self.on_host_removed: Optional[Callable] = None
355355

356356
async def start(self):
357357
# Set up and register the service on ths bus
@@ -414,51 +414,51 @@ def _name_owner_changed(self, message):
414414
self.StatusNotifierHostUnregistered(name)
415415

416416
@method()
417-
def RegisterStatusNotifierItem(self, service: 's'): # noqa: F821, N802
417+
def RegisterStatusNotifierItem(self, service: 's'): # type: ignore # noqa: F821, N802
418418
if service not in self._items:
419419
self._items.append(service)
420420
self.StatusNotifierItemRegistered(service)
421421

422422
@method()
423-
def RegisterStatusNotifierHost(self, service: 's'): # noqa: F821, N802
423+
def RegisterStatusNotifierHost(self, service: 's'): # type: ignore # noqa: F821, N802
424424
if service not in self._hosts:
425425
self._hosts.append(service)
426426
self.StatusNotifierHostRegistered(service)
427427

428428
@dbus_property(access=PropertyAccess.READ)
429-
def RegisteredStatusNotifierItems(self) -> 'as': # noqa: F722, F821, N802
429+
def RegisteredStatusNotifierItems(self) -> 'as': # type: ignore # noqa: F722, F821, N802
430430
return self._items
431431

432432
@dbus_property(access=PropertyAccess.READ)
433-
def IsStatusNotifierHostRegistered(self) -> 'b': # noqa: F821, N802
433+
def IsStatusNotifierHostRegistered(self) -> 'b': # type: ignore # noqa: F821, N802
434434
# Note: applications may not register items unless this
435435
# returns True
436436
return len(self._hosts) > 0
437437

438438
@dbus_property(access=PropertyAccess.READ)
439-
def ProtocolVersion(self) -> 'i': # noqa: F821, N802
439+
def ProtocolVersion(self) -> 'i': # type: ignore # noqa: F821, N802
440440
return PROTOCOL_VERSION
441441

442442
@signal()
443-
def StatusNotifierItemRegistered(self, service) -> 's': # noqa: F821, N802
443+
def StatusNotifierItemRegistered(self, service) -> 's': # type: ignore # noqa: F821, N802
444444
if self.on_item_added is not None:
445445
self.on_item_added(service)
446446
return service
447447

448448
@signal()
449-
def StatusNotifierItemUnregistered(self, service) -> 's': # noqa: F821, N802
449+
def StatusNotifierItemUnregistered(self, service) -> 's': # type: ignore # noqa: F821, N802
450450
if self.on_item_removed is not None:
451451
self.on_item_removed(service)
452452
return service
453453

454454
@signal()
455-
def StatusNotifierHostRegistered(self, service) -> 's': # noqa: F821, N802
455+
def StatusNotifierHostRegistered(self, service) -> 's': # type: ignore # noqa: F821, N802
456456
if self.on_host_added is not None:
457457
self.on_host_added(service)
458458
return service
459459

460460
@signal()
461-
def StatusNotifierHostUnregistered(self, service) -> 's': # noqa: F821, N802
461+
def StatusNotifierHostUnregistered(self, service) -> 's': # type: ignore # noqa: F821, N802
462462
if self.on_host_removed is not None:
463463
self.on_host_removed(service)
464464
return service

‎tox.ini‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ deps =
2828
pytest-cov >= 2.10.1
2929
setuptools >= 40.5.0
3030
xcffib >= 0.10.1
31-
mypy
3231
bowler
3332
xkbcommon >= 0.3
3433
pywayland >= 0.4.4
@@ -81,7 +80,9 @@ commands =
8180
deps =
8281
mypy
8382
bowler
83+
dbus-next
8484
xcffib >= 0.10.1
85+
PyGObject
8586
pytest >= 6.2.1
8687
types-python-dateutil
8788
types-pytz

0 commit comments

Comments
 (0)