Skip to content

Commit

Permalink
#3930 replace 'Optional' with '| None'
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jul 27, 2023
1 parent 6171915 commit d2ba763
Show file tree
Hide file tree
Showing 113 changed files with 434 additions and 433 deletions.
20 changes: 10 additions & 10 deletions xpra/child_reaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import os
import signal
from typing import Dict, Any, Optional, Callable
from typing import Any, Callable
from gi.repository import GLib # @UnresolvedImport

from xpra.util import envint, envbool
Expand All @@ -33,13 +33,13 @@ class ProcInfo:
ignore : bool
forget : bool
dead : bool
returncode : Optional[int]
callback : Optional[Callable]
returncode : int | None
callback : Callable | None
process : Any
def __repr__(self):
return f"ProcInfo({self.pid} : {self.command})"

def get_info(self) -> Dict[str,Any]:
def get_info(self) -> dict[str,Any]:
info = {
"pid" : self.pid,
"name" : self.name,
Expand Down Expand Up @@ -120,7 +120,7 @@ def poll(self) -> bool:
self.add_dead_process(procinfo)
return True

def set_quit_callback(self, cb:Callable) -> None:
def set_quit_callback(self, cb:callable) -> None:
self._quit = cb

def check(self) -> bool:
Expand Down Expand Up @@ -149,7 +149,7 @@ def _sigchld(self, signum, frame_str) -> None:
log("sigchld(%s, %s)", signum, frame_str)
self.reap()

def get_proc_info(self, pid : int) -> Optional[ProcInfo]:
def get_proc_info(self, pid : int) -> ProcInfo | None:
for proc_info in tuple(self._proc_info):
if proc_info.pid==pid:
return proc_info
Expand Down Expand Up @@ -210,17 +210,17 @@ def reap(self) -> None:
break
self.add_dead_pid(pid)

def get_info(self) -> Dict[Any,Any]:
def get_info(self) -> dict[Any,Any]:
iv = tuple(self._proc_info)
info : Dict[Any,Any] = {
info : dict[Any,Any] = {
"children" : {
"total" : len(iv),
"dead" : len(tuple(True for x in iv if x.dead)),
"ignored" : len(tuple(True for x in iv if x.ignore)),
}
}
pi = sorted(self._proc_info, key=lambda x: x.pid, reverse=True)
cinfo : Dict[int,Any] = info.setdefault("child", {})
cinfo : dict[int,Any] = info.setdefault("child", {})
for i, procinfo in enumerate(pi):
d = {}
for k in ("name", "command", "ignore", "forget", "returncode", "dead", "pid"):
Expand All @@ -231,7 +231,7 @@ def get_info(self) -> Dict[Any,Any]:
cinfo[i] = d
return info

singleton : Optional[ChildReaper] = None
singleton : ChildReaper | None = None
def getChildReaper() -> ChildReaper:
global singleton
if singleton is None:
Expand Down
4 changes: 2 additions & 2 deletions xpra/client/auth/u2f_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import logging
import binascii
from typing import Tuple, Optional
from typing import Tuple

from xpra.os_util import load_binary_file, strtobytes, osexpand, bytestostr
from xpra.log import Logger, is_debug_enabled
Expand All @@ -27,7 +27,7 @@ def __repr__(self):
def get_digest() -> str:
return "u2f"

def handle(self, challenge, digest:str, prompt:str) -> Optional[Tuple[bytes,bytes]]: # pylint: disable=unused-argument
def handle(self, challenge, digest:str, prompt:str) -> Tuple[bytes,bytes] | None: # pylint: disable=unused-argument
if not digest.startswith("u2f:"):
log("%s is not a u2f challenge", digest)
return None
Expand Down
4 changes: 2 additions & 2 deletions xpra/client/gl/gl_window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import time
from time import monotonic
from typing import Dict, Tuple, Any, Optional, Callable, Iterable, List
from typing import Dict, Tuple, Any, Callable, Iterable, List
from contextlib import AbstractContextManager
from gi.repository import GLib # @UnresolvedImport

Expand Down Expand Up @@ -272,7 +272,7 @@ class GLWindowBackingBase(WindowBackingBase):

def __init__(self, wid : int, window_alpha : bool, pixel_depth : int=0):
self.wid : int = wid
self.texture_pixel_format : Optional[IntConstant] = None
self.texture_pixel_format : IntConstant | None = None
#this is the pixel format we are currently updating the fbo with
#can be: "YUV420P", "YUV422P", "YUV444P", "GBRP" or None when not initialized yet.
self.pixel_format : str = ""
Expand Down
10 changes: 5 additions & 5 deletions xpra/client/gtk3/bug_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os.path
import sys
import time
from typing import Dict, Optional, Callable, Tuple
from typing import Dict, Callable, Tuple
from gi.repository import Gtk, Gdk # @UnresolvedImport

from xpra.common import ScreenshotData, noop
Expand All @@ -33,15 +33,15 @@ def __init__(self):
self.checkboxes = {}
self.server_log = None
self.show_about = True
self.get_server_info : Optional[Callable] = None
self.get_server_info : Callable | None = None
self.opengl_info : Dict = {}
self.includes : Dict = {}
self.window : Optional[Gtk.Window] = None
self.description : Optional[Gtk.TextView] = None
self.window : Gtk.Window | None = None
self.description : Gtk.TextView | None = None
self.toggles : Tuple = ()

def init(self, show_about:bool=True,
get_server_info:Optional[Callable]=None,
get_server_info:Callable | None=None,
opengl_info=None, includes=None):
self.show_about = show_about
self.get_server_info = get_server_info
Expand Down
6 changes: 3 additions & 3 deletions xpra/client/gtk3/gtk_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from time import monotonic
from subprocess import Popen, PIPE
from threading import Event
from typing import Dict, Any, List, Type, Tuple, Optional
from typing import Dict, Any, List, Type, Tuple
from gi.repository import Gtk, Gdk, GdkPixbuf # @UnresolvedImport

from xpra.client.gtk3.gtk_client_window_base import HAS_X11_BINDINGS, XSHAPE
Expand Down Expand Up @@ -85,8 +85,8 @@ class GTKXpraClient(GObjectXpraClient, UIXpraClient):
for signal_name in UIXpraClient.__signals__:
__gsignals__[signal_name] = no_arg_signal

ClientWindowClass : Optional[Type] = None
GLClientWindowClass : Optional[Type] = None
ClientWindowClass : Type | None = None
GLClientWindowClass : Type | None = None

def __init__(self):
GObjectXpraClient.__init__(self)
Expand Down
4 changes: 2 additions & 2 deletions xpra/client/gtk3/gtk_client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os.path
from time import monotonic
from urllib.parse import unquote
from typing import Set, List, Tuple, Dict, Callable, Optional, Union
from typing import Set, List, Tuple, Dict, Callable, Union
from cairo import ( #pylint: disable=no-name-in-module
RectangleInt, Region, # @UnresolvedImport
OPERATOR_OVER, LINE_CAP_ROUND, # @UnresolvedImport
Expand Down Expand Up @@ -831,7 +831,7 @@ def adjusted_position(self, ox, oy) -> Tuple[int,int]:
return ox, oy


def calculate_window_offset(self, wx:int, wy:int, ww:int, wh:int) -> Optional[Tuple[int,int]]:
def calculate_window_offset(self, wx:int, wy:int, ww:int, wh:int) -> Tuple[int,int] | None:
ss = self._client._current_screen_sizes
if not ss:
return None
Expand Down
3 changes: 1 addition & 2 deletions xpra/client/gtk3/gtk_tray_menu_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import re
from gi.repository import GLib, Gtk # @UnresolvedImport
from typing import Optional

from xpra.util import (
ConnectionMessage,
Expand Down Expand Up @@ -926,7 +925,7 @@ def make_avsyncmenuitem(self):
current_value = 0
if not self.client.av_sync:
current_value = None
def syncitem(label, delta:Optional[int]=0):
def syncitem(label, delta:int|None=0):
c = Gtk.CheckMenuItem(label=label)
c.set_draw_as_radio(True)
c.set_active(current_value==delta)
Expand Down
6 changes: 3 additions & 3 deletions xpra/client/gtk3/menu_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import os
import re
from typing import Callable, Optional
from typing import Callable

import gi
gi.require_version('Gtk', '3.0') # @UndefinedVariable
Expand Down Expand Up @@ -99,7 +99,7 @@ def load_pixbuf(data) -> GdkPixbuf.Pixbuf:
loader.close()
return loader.get_pixbuf()

def get_appimage(app_name, icondata=None, menu_icon_size=24) -> Optional[Gtk.Image]:
def get_appimage(app_name, icondata=None, menu_icon_size=24) -> Gtk.Image | None:
pixbuf = None
if app_name and not icondata:
#try to load from our icons:
Expand Down Expand Up @@ -425,7 +425,7 @@ def menuitem(self, title, icon_name=None, tooltip=None, cb=None, **kwargs) -> Gt
image = self.get_image(icon_name, icon_size)
return menuitem(title, image, tooltip, cb)

def checkitem(self, title, cb:Optional[Callable]=None, active=False) -> Gtk.CheckMenuItem:
def checkitem(self, title, cb:Callable|None=None, active=False) -> Gtk.CheckMenuItem:
""" Utility method for easily creating a CheckMenuItem """
check_item = Gtk.CheckMenuItem(label=title)
check_item.set_active(active)
Expand Down
6 changes: 3 additions & 3 deletions xpra/client/gui/tray_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from typing import Tuple, Callable, Optional, Deque
from typing import Tuple, Callable, Deque
from time import monotonic
from collections import deque

Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(self, _client, app_id, menu, tooltip:str, icon_filename:str,
self.tray_widget = None
self.default_icon_filename = icon_filename #ie: "xpra" or "/path/to/xpra.png"
#some implementations need this for guessing the geometry (see recalculate_geometry):
self.geometry_guess : Optional[Tuple[int,int,int,int]] = None
self.geometry_guess : Tuple[int,int,int,int] | None = None
self.tray_event_locations : Deque[Tuple[int,int]] = deque(maxlen=512)
self.default_icon_extension = "png"
self.icon_timestamp = 0.0
Expand Down Expand Up @@ -67,7 +67,7 @@ def get_orientation(self):
def get_geometry(self):
raise NotImplementedError

def get_size(self) -> Optional[Tuple[int,int]]:
def get_size(self) -> Tuple[int,int] | None:
g = self.get_geometry()
if g is None:
return None
Expand Down
4 changes: 2 additions & 2 deletions xpra/client/mixins/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from typing import Dict, Any, Callable, Tuple, Optional
from typing import Dict, Any, Callable, Tuple
from gi.repository import GLib # @UnresolvedImport

from xpra.platform.paths import get_icon_filename
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self):
self.av_sync_delta : int = AV_SYNC_DELTA
self.audio_properties : typedict = typedict()
#audio state:
self.on_sink_ready : Optional[Callable] = None
self.on_sink_ready : Callable | None = None
self.audio_sink = None
self.audio_sink_sequence : int = 0
self.server_audio_eos_sequence : bool = False
Expand Down
6 changes: 3 additions & 3 deletions xpra/client/mixins/window_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from time import sleep, time, monotonic
from queue import Queue
from threading import Thread
from typing import Dict, List, Tuple, Any, Type, Callable, Optional
from typing import Dict, List, Tuple, Any, Type, Callable
from gi.repository import GLib # @UnresolvedImport

from xpra.platform.gui import (
Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(self):

#draw thread:
self._draw_queue = Queue()
self._draw_thread : Optional[Thread] = None
self._draw_thread : Thread | None = None
self._draw_counter : int = 0

#statistics and server info:
Expand Down Expand Up @@ -624,7 +624,7 @@ def make_system_tray(self, *args):
return make_instance(tc, self, *args)

# noinspection PyMethodMayBeStatic
def get_system_tray_classes(self) -> Tuple[Optional[Type],...]:
def get_system_tray_classes(self) -> Tuple[Type | None,...]:
#subclasses may add their toolkit specific variants, if any
#by overriding this method
#use the native ones first:
Expand Down
10 changes: 5 additions & 5 deletions xpra/clipboard/clipboard_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
from time import monotonic
from io import BytesIO
from typing import Tuple, List, Dict, Callable, Optional, Any, Iterable
from typing import Tuple, List, Dict, Callable, Any, Iterable
from gi.repository import GLib # @UnresolvedImport

from xpra.common import noop
Expand All @@ -29,7 +29,7 @@

ALL_CLIPBOARDS : Tuple[str, ...] = tuple(PLATFORM_CLIPBOARDS)
CLIPBOARDS : List[str] = list(PLATFORM_CLIPBOARDS)
CLIPBOARDS_ENV : Optional[str] = os.environ.get("XPRA_CLIPBOARDS")
CLIPBOARDS_ENV : str | None = os.environ.get("XPRA_CLIPBOARDS")
if CLIPBOARDS_ENV is not None:
CLIPBOARDS = [x.upper().strip() for x in CLIPBOARDS_ENV.split(",")]
del CLIPBOARDS_ENV
Expand Down Expand Up @@ -351,7 +351,7 @@ def init_proxies(self, selections : Iterable[str]) -> None:
log("%s.init_proxies : %s", self, self._clipboard_proxies)

def init_translation(self, kwargs) -> None:
def getselection(name) -> Optional[str]:
def getselection(name) -> str | None:
v = kwargs.get(f"clipboard.{name}") #ie: clipboard.remote
env_value = os.environ.get(f"XPRA_TRANSLATEDCLIPBOARD_{name.upper()}_SELECTION")
selections = kwargs.get(f"clipboards.{name}") #ie: clipboards.remote
Expand Down Expand Up @@ -412,14 +412,14 @@ def client_reset(self) -> None:
""" overriden in subclasses to try to reset the state """

def set_direction(self, can_send:bool, can_receive:bool,
max_send_size:Optional[int]=None, max_receive_size:Optional[int]=None) -> None:
max_send_size:int|None=None, max_receive_size:int|None=None) -> None:
self.can_send = can_send
self.can_receive = can_receive
self.set_limits(max_send_size, max_receive_size)
for proxy in self._clipboard_proxies.values():
proxy.set_direction(can_send, can_receive)

def set_limits(self, max_send_size:Optional[int], max_receive_size:Optional[int]) -> None:
def set_limits(self, max_send_size:int|None, max_receive_size:int|None) -> None:
if max_send_size is not None:
self.max_clipboard_send_size = max_send_size
if max_receive_size is not None:
Expand Down
4 changes: 2 additions & 2 deletions xpra/clipboard/clipboard_timeout_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from typing import Dict, Tuple, Optional, List, Any
from typing import Dict, Tuple, List, Any

from gi.repository import GLib # @UnresolvedImport

Expand Down Expand Up @@ -41,7 +41,7 @@ def cleanup(self) -> None:
def make_proxy(self, selection:str):
raise NotImplementedError()

def _get_proxy(self, selection:str) -> Optional[ClipboardProxyCore]:
def _get_proxy(self, selection:str) -> ClipboardProxyCore | None:
proxy = self._clipboard_proxies.get(selection)
if not proxy:
log.warn("Warning: no clipboard proxy for '%s'", selection)
Expand Down
4 changes: 2 additions & 2 deletions xpra/codecs/codec_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pylint: disable=line-too-long

import binascii
from typing import Dict, Tuple, Optional, Callable
from typing import Dict, Tuple, Callable

from xpra.util import csv, typedict, roundup
from xpra.log import Logger
Expand Down Expand Up @@ -312,7 +312,7 @@ def testdecoder(decoder_module, full:bool):
return tuple(codecs)

def testdecoding(decoder_module, encoding:str, full:bool):
test_data_set : Optional[Dict[str,Dict[Tuple[int,int],Tuple[bytes,...]]]] = TEST_COMPRESSED_DATA.get(encoding)
test_data_set : Dict[str,Dict[Tuple[int,int],Tuple[bytes,...]]] | None = TEST_COMPRESSED_DATA.get(encoding)
for cs in decoder_module.get_input_colorspaces(encoding):
min_w, min_h = decoder_module.get_min_size(encoding)
test_data : Dict[Tuple[int,int],Tuple[bytes,...]] = {}
Expand Down
4 changes: 2 additions & 2 deletions xpra/codecs/gstreamer/codec_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os
from queue import Queue, Empty
from typing import Tuple, Dict, Any, Callable, Optional
from typing import Tuple, Dict, Any, Callable

from xpra.util import typedict, envint, parse_simple_dict
from xpra.os_util import OSX
Expand Down Expand Up @@ -189,7 +189,7 @@ def get_video_encoder_caps(encoder:str="x264enc") -> Dict[str,Any]:
"stream-format" : "byte-stream",
}

def get_video_encoder_options(encoder:str="x264", profile:str="", options:Optional[typedict]=None):
def get_video_encoder_options(encoder:str="x264", profile:str="", options:typedict|None=None):
eopts = get_default_encoder_options().get(encoder, {})
eopts["name"] = "encoder"
if encoder=="x264enc" and options:
Expand Down
Loading

0 comments on commit d2ba763

Please sign in to comment.