Skip to content

Commit

Permalink
fix: more cython3 optional fixes (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Aug 2, 2023
1 parent df7f57b commit 5b6cbc5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/dbus_fast/aio/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _write_without_remove_writer(self) -> None:
"""Call the write callback without removing the writer."""
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
if msg is not None:
self.buffer_message(msg, future)
Expand Down Expand Up @@ -158,9 +158,9 @@ class MessageBus(BaseMessageBus):

def __init__(
self,
bus_address: str = None,
bus_address: Optional[str] = None,
bus_type: BusType = BusType.SESSION,
auth: Authenticator = None,
auth: Optional[Authenticator] = None,
negotiate_unix_fd: bool = False,
) -> None:
super().__init__(bus_address, bus_type, ProxyObject, negotiate_unix_fd)
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_fast/aio/message_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def build_message_reader(
process: Callable[[Message], None],
finalize: Callable[[Optional[Exception]], None],
negotiate_unix_fd: bool,
) -> None:
) -> Callable[[], None]:
"""Build a callable that reads messages from the unmarshaller and passes them to the process function."""
unmarshaller = Unmarshaller(None, sock, negotiate_unix_fd)

Expand Down
2 changes: 1 addition & 1 deletion src/dbus_fast/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AuthExternal(Authenticator):
: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.negotiating_fds: bool = False
self.uid: Optional[int] = uid
Expand Down
13 changes: 9 additions & 4 deletions src/dbus_fast/glib/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class MessageBus(BaseMessageBus):

def __init__(
self,
bus_address: str = None,
bus_address: Optional[str] = None,
bus_type: BusType = BusType.SESSION,
auth: Authenticator = None,
auth: Optional[Authenticator] = None,
):
if _import_error:
raise _import_error
Expand All @@ -185,7 +185,10 @@ def _on_message(self, msg: Message) -> None:
)

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.
Expand Down Expand Up @@ -272,7 +275,9 @@ def connect_notify(bus, err):
def call(
self,
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
daemon.
Expand Down
21 changes: 12 additions & 9 deletions src/dbus_fast/introspection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import xml.etree.ElementTree as ET
from typing import List, Union
from typing import List, Optional, Union

from .constants import ArgDirection, PropertyAccess
from .errors import InvalidIntrospectionError
Expand Down Expand Up @@ -31,8 +31,8 @@ class Arg:
def __init__(
self,
signature: Union[SignatureType, str],
direction: List[ArgDirection] = None,
name: str = None,
direction: Optional[List[ArgDirection]] = None,
name: Optional[str] = None,
):
if name is not None:
assert_member_name_valid(name)
Expand Down Expand Up @@ -105,7 +105,7 @@ class Signal:
- :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:
assert_member_name_valid(name)

Expand Down Expand Up @@ -312,9 +312,9 @@ class Interface:
def __init__(
self,
name: str,
methods: List[Method] = None,
signals: List[Signal] = None,
properties: List[Property] = None,
methods: Optional[List[Method]] = None,
signals: Optional[List[Signal]] = None,
properties: Optional[List[Property]] = None,
):
assert_interface_name_valid(name)

Expand Down Expand Up @@ -395,7 +395,10 @@ class Node:
"""

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:
raise InvalidIntrospectionError('child nodes must have a "name" attribute')
Expand Down Expand Up @@ -487,7 +490,7 @@ def indent(elem, level=0):
return header + ET.tostring(xml, encoding="unicode").rstrip()

@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.
The default interfaces include:
Expand Down
10 changes: 5 additions & 5 deletions src/dbus_fast/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, fn, name, disabled=False):
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.
The parameters and return value must each be annotated with a signature
Expand Down Expand Up @@ -149,7 +149,7 @@ def __init__(self, fn, name, disabled=False):
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.
The signal is broadcast on the bus when the decorated class method is
Expand Down Expand Up @@ -271,7 +271,7 @@ def setter(self, fn, **kwargs):

def dbus_property(
access: PropertyAccess = PropertyAccess.READWRITE,
name: str = None,
name: Optional[str] = None,
disabled: bool = False,
):
"""A decorator to mark a class method of a :class:`ServiceInterface` to be a DBus property.
Expand Down Expand Up @@ -350,9 +350,9 @@ def __init__(self, name: str):
self.__properties: List[_Property] = []
self.__signals: List[_Signal] = []
self.__buses = set()
self.__handlers: dict[
self.__handlers: Dict[
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)):
Expand Down

0 comments on commit 5b6cbc5

Please sign in to comment.