fix: more cython3 optional fixes (#219)

This commit is contained in:
J. Nick Koston
2023-08-02 09:32:57 -10:00
committed by GitHub
parent df7f57b392
commit 5b6cbc560e
6 changed files with 31 additions and 23 deletions

View File

@@ -104,7 +104,7 @@ class _MessageWriter:
"""Call the write callback without removing the writer.""" """Call the write callback without removing the writer."""
self.write_callback(remove_writer=False) self.write_callback(remove_writer=False)
def schedule_write(self, msg: Message = None, future=None) -> None: def schedule_write(self, msg: Optional[Message] = None, future=None) -> None:
queue_is_empty = not self.messages queue_is_empty = not self.messages
if msg is not None: if msg is not None:
self.buffer_message(msg, future) self.buffer_message(msg, future)
@@ -158,9 +158,9 @@ class MessageBus(BaseMessageBus):
def __init__( def __init__(
self, self,
bus_address: str = None, bus_address: Optional[str] = None,
bus_type: BusType = BusType.SESSION, bus_type: BusType = BusType.SESSION,
auth: Authenticator = None, auth: Optional[Authenticator] = None,
negotiate_unix_fd: bool = False, negotiate_unix_fd: bool = False,
) -> None: ) -> None:
super().__init__(bus_address, bus_type, ProxyObject, negotiate_unix_fd) super().__init__(bus_address, bus_type, ProxyObject, negotiate_unix_fd)

View File

@@ -11,7 +11,7 @@ def build_message_reader(
process: Callable[[Message], None], process: Callable[[Message], None],
finalize: Callable[[Optional[Exception]], None], finalize: Callable[[Optional[Exception]], None],
negotiate_unix_fd: bool, negotiate_unix_fd: bool,
) -> None: ) -> Callable[[], None]:
"""Build a callable that reads messages from the unmarshaller and passes them to the process function.""" """Build a callable that reads messages from the unmarshaller and passes them to the process function."""
unmarshaller = Unmarshaller(None, sock, negotiate_unix_fd) unmarshaller = Unmarshaller(None, sock, negotiate_unix_fd)

View File

@@ -65,7 +65,7 @@ class AuthExternal(Authenticator):
:sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol :sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
""" """
def __init__(self, uid: int = None) -> None: def __init__(self, uid: Optional[int] = None) -> None:
self.negotiate_unix_fd: bool = False self.negotiate_unix_fd: bool = False
self.negotiating_fds: bool = False self.negotiating_fds: bool = False
self.uid: Optional[int] = uid self.uid: Optional[int] = uid

View File

@@ -159,9 +159,9 @@ class MessageBus(BaseMessageBus):
def __init__( def __init__(
self, self,
bus_address: str = None, bus_address: Optional[str] = None,
bus_type: BusType = BusType.SESSION, bus_type: BusType = BusType.SESSION,
auth: Authenticator = None, auth: Optional[Authenticator] = None,
): ):
if _import_error: if _import_error:
raise _import_error raise _import_error
@@ -185,7 +185,10 @@ class MessageBus(BaseMessageBus):
) )
def connect( def connect(
self, connect_notify: Callable[["MessageBus", Optional[Exception]], None] = None self,
connect_notify: Optional[
Callable[["MessageBus", Optional[Exception]], None]
] = None,
): ):
"""Connect this message bus to the DBus daemon. """Connect this message bus to the DBus daemon.
@@ -272,7 +275,9 @@ class MessageBus(BaseMessageBus):
def call( def call(
self, self,
msg: Message, msg: Message,
reply_notify: Callable[[Optional[Message], Optional[Exception]], None] = None, reply_notify: Optional[
Callable[[Optional[Message], Optional[Exception]], None]
] = None,
): ):
"""Send a method call and asynchronously wait for a reply from the DBus """Send a method call and asynchronously wait for a reply from the DBus
daemon. daemon.

View File

@@ -1,5 +1,5 @@
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from typing import List, Union from typing import List, Optional, Union
from .constants import ArgDirection, PropertyAccess from .constants import ArgDirection, PropertyAccess
from .errors import InvalidIntrospectionError from .errors import InvalidIntrospectionError
@@ -31,8 +31,8 @@ class Arg:
def __init__( def __init__(
self, self,
signature: Union[SignatureType, str], signature: Union[SignatureType, str],
direction: List[ArgDirection] = None, direction: Optional[List[ArgDirection]] = None,
name: str = None, name: Optional[str] = None,
): ):
if name is not None: if name is not None:
assert_member_name_valid(name) assert_member_name_valid(name)
@@ -105,7 +105,7 @@ class Signal:
- :class:`InvalidMemberNameError <dbus_fast.InvalidMemberNameError>` - If the name of the signal is not a valid member name. - :class:`InvalidMemberNameError <dbus_fast.InvalidMemberNameError>` - If the name of the signal is not a valid member name.
""" """
def __init__(self, name: str, args: List[Arg] = None): def __init__(self, name: Optional[str], args: Optional[List[Arg]] = None):
if name is not None: if name is not None:
assert_member_name_valid(name) assert_member_name_valid(name)
@@ -312,9 +312,9 @@ class Interface:
def __init__( def __init__(
self, self,
name: str, name: str,
methods: List[Method] = None, methods: Optional[List[Method]] = None,
signals: List[Signal] = None, signals: Optional[List[Signal]] = None,
properties: List[Property] = None, properties: Optional[List[Property]] = None,
): ):
assert_interface_name_valid(name) assert_interface_name_valid(name)
@@ -395,7 +395,10 @@ class Node:
""" """
def __init__( def __init__(
self, name: str = None, interfaces: List[Interface] = None, is_root: bool = True self,
name: Optional[str] = None,
interfaces: Optional[List[Interface]] = None,
is_root: bool = True,
): ):
if not is_root and not name: if not is_root and not name:
raise InvalidIntrospectionError('child nodes must have a "name" attribute') raise InvalidIntrospectionError('child nodes must have a "name" attribute')
@@ -487,7 +490,7 @@ class Node:
return header + ET.tostring(xml, encoding="unicode").rstrip() return header + ET.tostring(xml, encoding="unicode").rstrip()
@staticmethod @staticmethod
def default(name: str = None) -> "Node": def default(name: Optional[str] = None) -> "Node":
"""Create a :class:`Node` with the default interfaces supported by this library. """Create a :class:`Node` with the default interfaces supported by this library.
The default interfaces include: The default interfaces include:

View File

@@ -71,7 +71,7 @@ class _Method:
self.out_signature_tree = get_signature_tree(out_signature) self.out_signature_tree = get_signature_tree(out_signature)
def method(name: str = None, disabled: bool = False): def method(name: Optional[str] = None, disabled: bool = False):
"""A decorator to mark a class method of a :class:`ServiceInterface` to be a DBus service method. """A decorator to mark a class method of a :class:`ServiceInterface` to be a DBus service method.
The parameters and return value must each be annotated with a signature The parameters and return value must each be annotated with a signature
@@ -149,7 +149,7 @@ class _Signal:
self.introspection = intr.Signal(self.name, args) self.introspection = intr.Signal(self.name, args)
def signal(name: str = None, disabled: bool = False): def signal(name: Optional[str] = None, disabled: bool = False):
"""A decorator to mark a class method of a :class:`ServiceInterface` to be a DBus signal. """A decorator to mark a class method of a :class:`ServiceInterface` to be a DBus signal.
The signal is broadcast on the bus when the decorated class method is The signal is broadcast on the bus when the decorated class method is
@@ -271,7 +271,7 @@ class _Property(property):
def dbus_property( def dbus_property(
access: PropertyAccess = PropertyAccess.READWRITE, access: PropertyAccess = PropertyAccess.READWRITE,
name: str = None, name: Optional[str] = None,
disabled: bool = False, disabled: bool = False,
): ):
"""A decorator to mark a class method of a :class:`ServiceInterface` to be a DBus property. """A decorator to mark a class method of a :class:`ServiceInterface` to be a DBus property.
@@ -350,9 +350,9 @@ class ServiceInterface:
self.__properties: List[_Property] = [] self.__properties: List[_Property] = []
self.__signals: List[_Signal] = [] self.__signals: List[_Signal] = []
self.__buses = set() self.__buses = set()
self.__handlers: dict[ self.__handlers: Dict[
BaseMessageBus, BaseMessageBus,
dict[_Method, Callable[[Message, Callable[[Message], None]], None]], Dict[_Method, Callable[[Message, Callable[[Message], None]], None]],
] = {} ] = {}
for name, member in inspect.getmembers(type(self)): for name, member in inspect.getmembers(type(self)):