Skip to content

Commit

Permalink
fix: avoid expensive runtime inspection of known callables (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jan 16, 2024
1 parent e8ee4ba commit 0271825
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/dbus_fast/aio/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ async def introspect(
"""
future = self._loop.create_future()

super().introspect(bus_name, path, partial(self._reply_handler, future))
super().introspect(
bus_name,
path,
partial(self._reply_handler, future),
check_callback_type=False,
)

timer_handle = self._loop.call_later(
timeout, _future_set_exception, future, asyncio.TimeoutError
Expand Down Expand Up @@ -321,7 +326,9 @@ async def request_name(
"""
future = self._loop.create_future()

super().request_name(name, flags, partial(self._reply_handler, future))
super().request_name(
name, flags, partial(self._reply_handler, future), check_callback_type=False
)

return await future

Expand All @@ -343,7 +350,9 @@ async def release_name(self, name: str) -> ReleaseNameReply:
"""
future = self._loop.create_future()

super().release_name(name, partial(self._reply_handler, future))
super().release_name(
name, partial(self._reply_handler, future), check_callback_type=False
)

return await future

Expand Down
10 changes: 7 additions & 3 deletions src/dbus_fast/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def introspect(
bus_name: str,
path: str,
callback: Callable[[Optional[intr.Node], Optional[Exception]], None],
check_callback_type: bool = True,
) -> None:
"""Get introspection data for the node at the given path from the given
bus name.
Expand All @@ -280,7 +281,8 @@ def introspect(
- :class:`InvalidObjectPathError <dbus_fast.InvalidObjectPathError>` - If the given object path is not valid.
- :class:`InvalidBusNameError <dbus_fast.InvalidBusNameError>` - If the given bus name is not valid.
"""
BaseMessageBus._check_callback_type(callback)
if check_callback_type:
BaseMessageBus._check_callback_type(callback)

def reply_notify(reply: Optional[Message], err: Optional[Exception]) -> None:
try:
Expand Down Expand Up @@ -379,6 +381,7 @@ def request_name(
callback: Optional[
Callable[[Optional[RequestNameReply], Optional[Exception]], None]
] = None,
check_callback_type: bool = True,
) -> None:
"""Request that this message bus owns the given name.
Expand All @@ -395,7 +398,7 @@ def request_name(
"""
assert_bus_name_valid(name)

if callback is not None:
if callback is not None and check_callback_type:
BaseMessageBus._check_callback_type(callback)

if type(flags) is not NameFlag:
Expand Down Expand Up @@ -432,6 +435,7 @@ def release_name(
callback: Optional[
Callable[[Optional[ReleaseNameReply], Optional[Exception]], None]
] = None,
check_callback_type: bool = True,
) -> None:
"""Request that this message bus release the given name.
Expand All @@ -447,7 +451,7 @@ def release_name(
"""
assert_bus_name_valid(name)

if callback is not None:
if callback is not None and check_callback_type:
BaseMessageBus._check_callback_type(callback)

message = Message(
Expand Down

0 comments on commit 0271825

Please sign in to comment.