Skip to content

Add pydbus stubs #13921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions stubs/pydbus/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore Variant as it is probably not an intentional export
pydbus.__all__
# This is only used to add a method to Gio.DBusConnection. Likely only for internal use.
pydbus.bus.pydbus_property
# Flag value default is literal 0, but we can use nice enums for these
pydbus.bus_names.OwnMixin.own_name
pydbus.bus_names.WatchMixin.watch_name
pydbus.subscription.SubscriptionMixin.subscribe
# Necessary to access D-Bus methods and properties
pydbus.proxy.ProxyObject.__getattr__
7 changes: 7 additions & 0 deletions stubs/pydbus/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version = "0.6.*"
requires = ["pygobject-stubs"]
upstream_repository = "https://github.com/LEW21/pydbus"

[tool.stubtest]
stubtest_requirements = ["pygobject"]
apt_dependencies = ["libcairo2-dev", "libgirepository-2.0-dev"]
3 changes: 3 additions & 0 deletions stubs/pydbus/pydbus/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .bus import SessionBus as SessionBus, SystemBus as SystemBus, connect as connect

__all__ = ["SessionBus", "SystemBus", "connect"]
2 changes: 2 additions & 0 deletions stubs/pydbus/pydbus/auto_names.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def auto_bus_name(bus_name: str) -> str: ...
def auto_object_path(bus_name: str, object_path: str | None = None) -> str: ...
48 changes: 48 additions & 0 deletions stubs/pydbus/pydbus/bus.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import types
from typing import TypeVar, type_check_only
from typing_extensions import Self

from gi.repository import Gio

from .bus_names import OwnMixin, WatchMixin
from .proxy import ProxyMixin
from .publication import PublicationMixin
from .registration import RegistrationMixin
from .request_name import RequestNameMixin
from .subscription import SubscriptionMixin

_T = TypeVar("_T")

def bus_get(type: Gio.BusType) -> Bus[object]: ...
def connect(address: str) -> Bus[object]: ...
@type_check_only
class _DBusOrgFreedesktopDBus:
# Incomplete interface to org.freedesktop.DBus
Features: list[str]

def GetId(self) -> str: ...

@type_check_only
class _DBusOrgFreedesktopPolicyKit1Authority:
# Incomplete interface to org.freedesktop.PolicyKit1.Authority
BackendFeatures: int # flags
BackendName: str
BackendVersion: str

class Bus(ProxyMixin[_T], RequestNameMixin[_T], OwnMixin, WatchMixin, SubscriptionMixin, RegistrationMixin[_T], PublicationMixin):
Type: type[Gio.BusType] = ...
autoclose: bool
con: Gio.DBusConnection

def __init__(self, gio_con: Gio.DBusConnection) -> None: ...
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None
) -> None: ...
@property
def dbus(self) -> _DBusOrgFreedesktopDBus: ...
@property
def polkit_authority(self) -> _DBusOrgFreedesktopPolicyKit1Authority: ...

def SystemBus() -> Bus[object]: ...
def SessionBus() -> Bus[object]: ...
53 changes: 53 additions & 0 deletions stubs/pydbus/pydbus/bus_names.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from collections.abc import Callable

from gi.repository import Gio

from .exitable import Exitable

class NameOwner(Exitable):
Flags: Gio.BusNameOwnerFlags

def __init__(
self,
con: Gio.DBusConnection,
name: str,
flags: Gio.BusNameOwnerFlags,
name_aquired_handler: Callable[[str], object],
name_lost_handler: Callable[[str], object],
) -> None: ...
def unown(self) -> None: ... # added by ExitableWithAliases('unown')

class NameWatcher(Exitable):
Flags: Gio.BusNameWatcherFlags

def __init__(
self,
con: Gio.DBusConnection,
name: str,
flags: Gio.BusNameWatcherFlags,
name_appeared_handler: Callable[[str], object],
name_vanished_handler: Callable[[str], object],
) -> None: ...
def unwatch(self) -> None: ... # added by ExitableWithAliases('unwatch')

class OwnMixin:
NameOwnerFlags: Gio.BusNameOwnerFlags

def own_name(
self,
name: str,
flags: Gio.BusNameOwnerFlags = ...,
name_aquired: Callable[[str], object] | None = ...,
name_lost: Callable[[str], object] | None = ...,
) -> NameOwner: ...

class WatchMixin:
NameWatcherFlags: Gio.BusNameWatcherFlags

def watch_name(
self,
name: str,
flags: Gio.BusNameWatcherFlags = ...,
name_appeared: Callable[[str], object] | None = ...,
name_vanished: Callable[[str], object] | None = ...,
) -> NameWatcher: ...
13 changes: 13 additions & 0 deletions stubs/pydbus/pydbus/exitable.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import types
from typing_extensions import Self

class Exitable:
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None = None,
exc_value: BaseException | None = None,
traceback: types.TracebackType | None = None,
) -> None: ...

def ExitableWithAliases(*exit_methods: str) -> Exitable: ...
44 changes: 44 additions & 0 deletions stubs/pydbus/pydbus/generic.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import types
from _typeshed import Unused
from collections.abc import Callable
from typing import Generic, TypeVar, overload
from typing_extensions import Self

class subscription:
callback_list: list[Callable[..., object]]
callback: Callable[..., object]

def __init__(self, callback_list: list[Callable[..., object]], callback: Callable[..., object]) -> None: ...
def unsubscribe(self) -> None: ...
def disconnect(self) -> None: ...
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None
) -> None: ...

_T = TypeVar("_T")

class bound_signal(Generic[_T]):
__signal__: signal[_T]
__self__: _T

def __init__(self, signal: signal[_T], instance: _T) -> None: ...
@property
def callbacks(self) -> list[Callable[..., object]]: ...
def connect(self, callback: Callable[..., object]) -> subscription: ...
def emit(self, *args: object) -> None: ...
def __call__(self, *args: object) -> None: ...

class signal(Generic[_T]):
map: dict[object, Callable[..., object]]

def __init__(self) -> None: ...
def connect(self, object: str, callback: Callable[..., object]) -> subscription: ...
def emit(self, object: str, *args: object) -> None: ...
@overload
def __get__(self, instance: None, owner: Unused) -> Self: ...
@overload
def __get__(self, instance: _T, owner: Unused) -> bound_signal[_T]: ...
def __set__(self, instance: Unused, value: Unused) -> None: ... # Always raises

bound_method: Callable[..., None] # type(signal().emit)
2 changes: 2 additions & 0 deletions stubs/pydbus/pydbus/identifier.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def isident(s: str, /) -> bool: ...
def filter_identifier(name: str) -> str: ...
27 changes: 27 additions & 0 deletions stubs/pydbus/pydbus/method_call_context.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Generic, NamedTuple, TypeVar

from gi.repository import Gio

from .bus import Bus

_T = TypeVar("_T")

class AuthorizationResult(NamedTuple):
is_authorized: bool
is_challenge: bool
details: dict[str, str]

class MethodCallContext(Generic[_T]):
def __init__(self, gdbus_method_invocation: Gio.DBusMethodInvocation) -> None: ...
@property
def bus(self) -> Bus[_T]: ...
@property
def sender(self) -> str: ...
@property
def object_path(self) -> str: ...
@property
def interface_name(self) -> str: ...
@property
def method_name(self) -> str: ...
def check_authorization(self, action_id: str, details: dict[str, str], interactive: bool = False) -> AuthorizationResult: ...
def is_authorized(self, action_id: str, details: dict[str, str], interactive: bool = False) -> bool: ...
Loading
Loading