--- a/libqtile/backend/base/window.py +++ b/libqtile/backend/base/window.py @@ -581,4 +581,4 @@ ) -WindowType = Window | Internal | Static +WindowType = typing.Union[Window, Internal, Static] --- a/libqtile/backend/wayland/core.py +++ b/libqtile/backend/wayland/core.py @@ -868,7 +868,7 @@ logger.debug("Signal: idle_inhibitor new_inhibitor") for win in self.qtile.windows_map.values(): - if isinstance(win, window.Window | window.Static): + if isinstance(win, (window.Window, window.Static)): win.surface.for_each_surface(win.add_idle_inhibitor, idle_inhibitor) if idle_inhibitor.data: # We break if the .data attribute was set, because that tells us --- a/libqtile/backend/wayland/window.py +++ b/libqtile/backend/wayland/window.py @@ -1113,7 +1113,7 @@ self.tree.node.raise_to_top() -WindowType = Window | Static | Internal +WindowType = typing.Union[Window, Static, Internal] class PointerConstraint(HasListeners): --- a/libqtile/bar.py +++ b/libqtile/bar.py @@ -767,4 +767,4 @@ self.window.keep_above(enable=True) -BarType = Bar | Gap +BarType = typing.Union[Bar, Gap] --- a/libqtile/command/graph.py +++ b/libqtile/command/graph.py @@ -26,7 +26,7 @@ from __future__ import annotations import abc -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union if TYPE_CHECKING: SelectorType = tuple[str, str | int | None] @@ -218,4 +218,4 @@ } -GraphType = CommandGraphNode | CommandGraphCall +GraphType = Union[CommandGraphNode, CommandGraphCall] --- a/libqtile/core/manager.py +++ b/libqtile/core/manager.py @@ -1417,7 +1417,7 @@ return [ i.info() for i in self.windows_map.values() - if not isinstance(i, base.Internal | _Widget) and isinstance(i, CommandObject) + if not isinstance(i, (base.Internal, _Widget)) and isinstance(i, CommandObject) ] @expose_command() --- a/libqtile/layout/screensplit.py +++ b/libqtile/layout/screensplit.py @@ -43,10 +43,10 @@ self, *, name: str, rect: Rect, layout: Layout, matches: list[_Match] = list() ) -> None: # Check that rect is correctly defined - if not isinstance(rect, tuple | list): + if not isinstance(rect, (tuple, list)): raise ValueError("Split rect should be a list/tuple.") - if len(rect) != 4 or not all(isinstance(x, float | int) for x in rect): + if len(rect) != 4 or not all(isinstance(x, (float, int)) for x in rect): raise ValueError("Split rect should have 4 float/int members.") if isinstance(layout, ScreenSplit): --- a/libqtile/utils.py +++ b/libqtile/utils.py @@ -31,7 +31,7 @@ from pathlib import Path from random import randint from shutil import which -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union try: from dbus_next import AuthError, Message, Variant @@ -44,8 +44,8 @@ from libqtile.log_utils import logger -ColorType = str | tuple[int, int, int] | tuple[int, int, int, float] -ColorsType = ColorType | list[ColorType] +ColorType = Union[str, tuple[int, int, int], tuple[int, int, int, float]] +ColorsType = Union[ColorType, list[ColorType]] if TYPE_CHECKING: from collections.abc import Callable, Coroutine from typing import Any, TypeVar @@ -112,7 +112,7 @@ Which is returned as (1.0, 0.0, 0.0, 0.5). """ - if isinstance(x, tuple | list): + if isinstance(x, (tuple, list)): if len(x) == 4: alpha = x[-1] else: @@ -152,7 +152,7 @@ Where a list of colours is passed, returns True if any colour is not fully opaque. """ - if isinstance(colour, str | tuple): + if isinstance(colour, (str, tuple)): return rgb(colour)[3] < 1 return any(has_transparency(c) for c in colour) @@ -161,7 +161,7 @@ """ Returns a tuple of (r, g, b) with no alpha. """ - if isinstance(colour, str | tuple): + if isinstance(colour, (str, tuple)): return tuple(x * 255.0 for x in rgb(colour)[:3]) return [remove_transparency(c) for c in colour] --- a/libqtile/widget/base.py +++ b/libqtile/widget/base.py @@ -35,7 +35,7 @@ import copy import math import subprocess -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from libqtile import bar, configurable, confreader from libqtile.command import interface @@ -714,7 +714,7 @@ @expose_command() def set_font( self, - font: str | None = None, + font: Union[str, None] = None, fontsize: int = 0, fontshadow: ColorType = "", ): --- a/libqtile/widget/helpers/status_notifier/statusnotifier.py +++ b/libqtile/widget/helpers/status_notifier/statusnotifier.py @@ -23,6 +23,8 @@ from pathlib import Path # dbus_next is incompatible with deferred type evaluation +from typing import Optional + import cairocffi from dbus_next import InterfaceNotFoundError, InvalidBusNameError, InvalidObjectPathError from dbus_next.aio import MessageBus @@ -472,10 +474,10 @@ self._items: list[str] = [] self._hosts: list[str] = [] self.service = service - self.on_item_added: Callable | None = None - self.on_host_added: Callable | None = None - self.on_item_removed: Callable | None = None - self.on_host_removed: Callable | None = None + self.on_item_added: Optional[Callable] = None + self.on_host_added: Optional[Callable] = None + self.on_item_removed: Optional[Callable] = None + self.on_host_removed: Optional[Callable] = None async def start(self): # Set up and register the service on ths bus @@ -616,9 +618,9 @@ async def start( self, - on_item_added: Callable | None = None, - on_item_removed: Callable | None = None, - on_icon_changed: Callable | None = None, + on_item_added: Optional[Callable] = None, + on_item_removed: Optional[Callable] = None, + on_icon_changed: Optional[Callable] = None, ): """ Starts the host if not already started. --- a/libqtile/widget/windowtabs.py +++ b/libqtile/widget/windowtabs.py @@ -50,7 +50,7 @@ width = config.pop("width", bar.STRETCH) base._TextBox.__init__(self, width=width, **config) self.add_defaults(WindowTabs.defaults) - if not isinstance(self.selected, tuple | list): + if not isinstance(self.selected, (tuple, list)): self.selected = (self.selected, self.selected) def _configure(self, qtile, bar):