Skip to content

Commit 1b118a4

Browse files
committed
Add pydbus stubs
1 parent a46eea7 commit 1b118a4

18 files changed

+561
-0
lines changed

stubs/pydbus/METADATA.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "0.6.*"
2+
requires = ["pygobject-stubs"]
3+
upstream_repository = "https://github.com/LEW21/pydbus"

stubs/pydbus/pydbus/__init__.pyi

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from gi.repository.GLib import Variant
2+
3+
from .bus import SessionBus, SystemBus, connect
4+
5+
__all__ = ["SessionBus", "SystemBus", "Variant", "connect"]

stubs/pydbus/pydbus/auto_names.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def auto_bus_name(bus_name: str) -> str: ...
2+
def auto_object_path(bus_name: str, object_path: str | None = None) -> str: ...

stubs/pydbus/pydbus/bus.pyi

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import types
2+
from typing import Any, Generic, Literal, TypedDict, TypeVar, overload
3+
from typing_extensions import Self
4+
5+
from gi.repository import Gio
6+
7+
from .bus_names import OwnMixin, WatchMixin
8+
from .generic import bound_signal
9+
from .proxy import CompositeObject, ProxyMixin
10+
from .publication import PublicationMixin
11+
from .registration import RegistrationMixin
12+
from .request_name import RequestNameMixin
13+
from .subscription import SubscriptionMixin
14+
15+
_T = TypeVar("_T")
16+
_ST = TypeVar("_ST") # signal type
17+
18+
def bus_get(type: Gio.BusType) -> Bus[object]: ...
19+
def connect(address: str) -> Bus[object]: ...
20+
21+
class DBusOrgFreedesktopDBus:
22+
# Incomplete interface to org.freedesktop.DBus
23+
Features: list[str]
24+
25+
def GetId(self) -> str: ...
26+
27+
class DBusOrgFreedesktopPolicyKit1Authority:
28+
# Incomplete interface to org.freedesktop.PolicyKit1.Authority
29+
BackendFeatures: int # flags
30+
BackendName: str
31+
BackendVersion: str
32+
33+
class OrgBluezAdapter1Dict(TypedDict, total=False):
34+
Address: str
35+
AddressType: Literal["public", "random"]
36+
Alias: str
37+
Class: int
38+
Connectable: bool
39+
Discoverable: bool
40+
DiscoverableTimeout: int
41+
Discovering: bool
42+
Manufacturer: int
43+
Modalias: str
44+
Name: str
45+
Pairable: bool
46+
PairableTimeout: int
47+
Powered: bool
48+
Roles: list[str]
49+
UUIDs: list[str]
50+
Version: int
51+
52+
class OrgBluezDevice1Dict(TypedDict, total=False):
53+
Adapter: str
54+
Address: str
55+
AddressType: Literal["public", "random"]
56+
Alias: str
57+
Appearance: int
58+
Blocked: bool
59+
Bonded: bool
60+
Class: int
61+
Connected: bool
62+
Icon: str
63+
LegacyPairing: bool
64+
Modalias: str
65+
Name: str
66+
Paired: bool
67+
ServicesResolved: bool
68+
Trusted: bool
69+
UUIDs: list[str]
70+
WakeAllowed: bool
71+
72+
class OrgBluezInput1Dict(TypedDict, total=False):
73+
ReconnectMode: str
74+
75+
class OrgBluezMedia1Dict(TypedDict, total=False):
76+
SupportedUUIDs: list[str]
77+
78+
class OrgBluezMediaControl1Dict(TypedDict, total=False):
79+
Connected: bool
80+
81+
class OrgBluezBattery1Dict(TypedDict, total=False):
82+
Percentage: int
83+
Source: str
84+
85+
class OrgBluezGattService1Dict(TypedDict, total=False):
86+
Device: str
87+
Handle: int
88+
Includes: list[str]
89+
Primary: bool
90+
UUID: str
91+
92+
class OrgBluezGattCharacteristic1Dict(TypedDict, total=False):
93+
Flags: list[str]
94+
Handle: int
95+
MTU: int
96+
Service: str
97+
UUID: str
98+
Value: list[int]
99+
100+
class OrgBluezGattDescriptor1Dict(TypedDict, total=False):
101+
Characteristic: str
102+
Handle: int
103+
UUID: str
104+
Value: list[int]
105+
106+
class OrgBluezLEAdvertisingManager1Dict(TypedDict, total=False):
107+
ActiveInstances: int
108+
SupportedCapabilities: dict[str, int] # e.g. MaxTxPower: 7
109+
SupportedFeatures: list[str]
110+
SupportedIncludes: list[str]
111+
SupportedInstances: int
112+
SupportedSecondaryChannels: list[str]
113+
114+
# This is for keys under /org/bluez/hci0/*
115+
OrgBluezDict = TypedDict(
116+
"OrgBluezDict",
117+
{
118+
"org.bluez.Adapter1": OrgBluezAdapter1Dict,
119+
"org.bluez.Battery1": OrgBluezBattery1Dict,
120+
"org.bluez.Device1": OrgBluezDevice1Dict,
121+
"org.bluez.GattCharacteristic1": OrgBluezGattCharacteristic1Dict,
122+
"org.bluez.GattDescriptor1": OrgBluezGattDescriptor1Dict,
123+
"org.bluez.GattService1": OrgBluezGattService1Dict,
124+
"org.bluez.Input1": OrgBluezInput1Dict,
125+
"org.bluez.LEAdvertisingManager1": OrgBluezLEAdvertisingManager1Dict,
126+
"org.bluez.Media1": OrgBluezMedia1Dict,
127+
"org.bluez.MediaControl1": OrgBluezMediaControl1Dict,
128+
# The following always appear as empty dictionaries on my system.
129+
"org.bluez.AgentManager1": dict[str, Any],
130+
"org.bluez.BatteryProviderManager1": dict[str, Any],
131+
"org.bluez.NetworkServer1": dict[str, Any],
132+
"org.bluez.ProfileManager1": dict[str, Any],
133+
"org.freedesktop.DBus.Introspectable": dict[str, Any],
134+
"org.freedesktop.DBus.Properties": dict[str, Any],
135+
},
136+
total=False,
137+
)
138+
139+
class OrgFreedesktopDBusObjectManager:
140+
@staticmethod
141+
def GetManagedObjects() -> dict[str, OrgBluezDict]: ...
142+
143+
class OrgBluez(CompositeObject[_T]):
144+
def __getitem__( # type: ignore[override]
145+
self, key: Literal["org.freedesktop.DBus.ObjectManager"]
146+
) -> OrgFreedesktopDBusObjectManager: ...
147+
148+
class OrgFreedesktopNotifications(CompositeObject[_T], Generic[_T, _ST]):
149+
Inhibited: bool
150+
ActivationToken: bound_signal[_ST]
151+
ActionInvoked: bound_signal[_ST]
152+
NotificationClosed: bound_signal[_ST]
153+
154+
def CloseNotification(self, id: int) -> None: ...
155+
def GetCapabilities(self) -> list[str]: ... # We could use Literal[] here but KDE also returns its own not in the spec.
156+
def GetServerInformation(self) -> tuple[str, str, str, str]: ...
157+
def Inhibit(self, name: str, reason: str, hints: dict[str, bool | bytes | int | str]) -> int | None: ...
158+
def Notify(
159+
self,
160+
app_name: str,
161+
replaces_id: int,
162+
app_icon: str,
163+
summary: str,
164+
body: str,
165+
actions: list[str],
166+
hints: dict[str, bool | bytes | int | str], # See https://specifications.freedesktop.org/notification-spec/1.3/hints.html
167+
expire_timeout: int,
168+
) -> int: ...
169+
def UnInhibit(self, key: int) -> int | None: ...
170+
171+
class Bus(ProxyMixin[_T], RequestNameMixin[_T], OwnMixin, WatchMixin, SubscriptionMixin, RegistrationMixin[_T], PublicationMixin):
172+
Type: type[Gio.BusType] = ...
173+
autoclose: bool
174+
con: Gio.DBusConnection
175+
176+
def __init__(self, gio_con: Gio.DBusConnection) -> None: ...
177+
def __enter__(self) -> Self: ...
178+
def __exit__(
179+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None
180+
) -> None: ...
181+
@property
182+
def dbus(self) -> DBusOrgFreedesktopDBus: ...
183+
@property
184+
def polkit_authority(self) -> DBusOrgFreedesktopPolicyKit1Authority: ...
185+
@overload # type: ignore[override]
186+
def get(self, bus_name: Literal[".Notifications"]) -> OrgFreedesktopNotifications[_T, object]: ...
187+
@overload
188+
def get(self, bus_name: Literal["org.freedesktop.Notifications"]) -> OrgFreedesktopNotifications[_T, object]: ...
189+
@overload
190+
def get(self, bus_name: Literal["org.bluez"], object_path: Literal["/"]) -> OrgBluez[_T]: ...
191+
@overload
192+
def get(self, bus_name: str, object_path: str) -> Any: ...
193+
194+
def SystemBus() -> Bus[object]: ...
195+
def SessionBus() -> Bus[object]: ...

stubs/pydbus/pydbus/bus_names.pyi

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from collections.abc import Callable
2+
3+
from gi.repository import Gio
4+
5+
from .exitable import Exitable
6+
7+
class NameOwner(Exitable):
8+
Flags: Gio.BusNameOwnerFlags
9+
10+
def __init__(
11+
self,
12+
con: Gio.DBusConnection,
13+
name: str,
14+
flags: Gio.BusNameOwnerFlags,
15+
name_aquired_handler: Callable[[str], None],
16+
name_lost_handler: Callable[[str], None],
17+
) -> None: ...
18+
def unown(self) -> None: ... # added by ExitableWithAliases('unown')
19+
20+
class NameWatcher(Exitable):
21+
Flags: Gio.BusNameWatcherFlags
22+
23+
def __init__(
24+
self,
25+
con: Gio.DBusConnection,
26+
name: str,
27+
flags: Gio.BusNameWatcherFlags,
28+
name_appeared_handler: Callable[[str], None],
29+
name_vanished_handler: Callable[[str], None],
30+
) -> None: ...
31+
def unwatch(self) -> None: ... # added by ExitableWithAliases('unwatch')
32+
33+
class OwnMixin:
34+
NameOwnerFlags: Gio.BusNameOwnerFlags
35+
36+
def own_name(
37+
self,
38+
name: str,
39+
flags: Gio.BusNameOwnerFlags = ...,
40+
name_aquired: Callable[[str], None] | None = ...,
41+
name_lost: Callable[[str], None] | None = ...,
42+
) -> NameOwner: ...
43+
44+
class WatchMixin:
45+
NameWatcherFlags: Gio.BusNameWatcherFlags
46+
47+
def watch_name(
48+
self,
49+
name: str,
50+
flags: Gio.BusNameWatcherFlags = ...,
51+
name_appeared: Callable[[str], None] | None = ...,
52+
name_vanished: Callable[[str], None] | None = ...,
53+
) -> NameWatcher: ...

stubs/pydbus/pydbus/exitable.pyi

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import types
2+
from collections.abc import Iterable
3+
from typing_extensions import Self
4+
5+
class Exitable:
6+
def __enter__(self) -> Self: ...
7+
def __exit__(
8+
self,
9+
exc_type: type[BaseException] | None = None,
10+
exc_value: BaseException | None = None,
11+
traceback: types.TracebackType | None = None,
12+
) -> None: ...
13+
14+
def ExitableWithAliases(*exit_methods: Iterable[str]) -> Exitable: ...

stubs/pydbus/pydbus/generic.pyi

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import types
2+
from _typeshed import Unused
3+
from collections.abc import Callable
4+
from typing import Generic, TypeVar, overload
5+
from typing_extensions import Self
6+
7+
class subscription:
8+
callback_list: list[Callable[..., object]]
9+
callback: Callable[..., object]
10+
11+
def __init__(self, callback_list: list[Callable[..., object]], callback: Callable[..., object]) -> None: ...
12+
def unsubscribe(self) -> None: ...
13+
def disconnect(self) -> None: ...
14+
def __enter__(self) -> Self: ...
15+
def __exit__(
16+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None
17+
) -> None: ...
18+
19+
_T = TypeVar("_T")
20+
21+
class bound_signal(Generic[_T]):
22+
__signal__: signal[_T]
23+
24+
def __init__(self, signal: signal[_T], instance: _T) -> None: ...
25+
@property
26+
def callbacks(self) -> list[Callable[..., object]]: ...
27+
def connect(self, callback: Callable[..., object]) -> subscription: ...
28+
def emit(self, *args: object) -> None: ...
29+
def __call__(self, *args: object) -> None: ...
30+
31+
class signal(Generic[_T]):
32+
map: dict[object, Callable[..., object]]
33+
34+
def __init__(self) -> None: ...
35+
def connect(self, object: str, callback: Callable[..., object]) -> subscription: ...
36+
def emit(self, object: str, *args: object) -> None: ...
37+
@overload
38+
def __get__(self, instance: None, owner: Unused) -> Self: ...
39+
@overload
40+
def __get__(self, instance: _T, owner: Unused) -> bound_signal[_T]: ...
41+
def __set__(self, instance: Unused, value: Unused) -> None: ... # Always raises
42+
43+
bound_method: Callable[..., None] # type(signal().emit)

stubs/pydbus/pydbus/identifier.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def isident(s: str) -> bool: ...
2+
def filter_identifier(name: str) -> str: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Generic, NamedTuple, TypeVar
2+
3+
from gi.repository import Gio
4+
5+
from .bus import Bus
6+
7+
_T = TypeVar("_T")
8+
9+
class AuthorizationResult(NamedTuple):
10+
is_authorized: bool
11+
is_challenge: bool
12+
details: dict[str, str]
13+
14+
class MethodCallContext(Generic[_T]):
15+
def __init__(self, gdbus_method_invocation: Gio.DBusMethodInvocation) -> None: ...
16+
@property
17+
def bus(self) -> Bus[_T]: ...
18+
@property
19+
def sender(self) -> str: ...
20+
@property
21+
def object_path(self) -> str: ...
22+
@property
23+
def interface_name(self) -> str: ...
24+
@property
25+
def method_name(self) -> str: ...
26+
def check_authorization(self, action_id: str, details: dict[str, str], interactive: bool = False) -> AuthorizationResult: ...
27+
def is_authorized(self, action_id: str, details: dict[str, str], interactive: bool = False) -> bool: ...

stubs/pydbus/pydbus/proxy.pyi

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import Generic, TypeVar
2+
from typing_extensions import Self
3+
from xml.etree.ElementTree import Element
4+
5+
from .bus import Bus
6+
7+
_T = TypeVar("_T")
8+
9+
class ProxyMixin(Generic[_T]):
10+
def get(self, bus_name: str, object_path: str | None = None, *, timeout: int | None = None) -> CompositeObject[_T]: ...
11+
12+
class ProxyObject(Generic[_T]):
13+
def __init__(self, bus: Bus[_T], bus_name: str, path: str, object: Self | None = None) -> None: ...
14+
def __getattr__(self, name: str) -> _T: ...
15+
def __setattr__(self, name: str, value: _T) -> None: ...
16+
17+
class CompositeObject(ProxyObject[_T]): # Inside CompositeInterface
18+
def __getitem__(self, iface: str) -> ProxyObject[_T]: ...
19+
20+
class interface(ProxyObject[_T]): # inside Interface
21+
@staticmethod
22+
def _Introspect() -> None: ...
23+
24+
def Interface(iface: Element) -> interface[object]: ...
25+
def CompositeInterface(introspection: Element) -> CompositeObject[object]: ...

stubs/pydbus/pydbus/proxy_method.pyi

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from _typeshed import Unused
2+
from inspect import Signature
3+
from typing import Generic, TypeVar
4+
5+
from .proxy import ProxyObject
6+
7+
_CT = TypeVar("_CT") # __call__ return type
8+
_GT = TypeVar("_GT") # __get__ return type
9+
_PT = TypeVar("_PT") # ProxyObject type
10+
put_signature_in_doc: bool = False
11+
12+
class DBUSSignature(Signature): ...
13+
14+
class ProxyMethod(Generic[_GT, _CT, _PT]):
15+
__signature__: DBUSSignature
16+
17+
def __init__(self, iface_name: str, method: str) -> None: ...
18+
def __call__(self, instance: ProxyObject[_PT], *args: object, timeout: int | None = None) -> _CT: ...
19+
def __get__(self, instance: ProxyObject[_PT], owner: Unused) -> _GT: ...

0 commit comments

Comments
 (0)