Skip to content

Commit 5acc62f

Browse files
committed
Use standard collections type hinting generics
Since Python 3.9 the standard collections like `list` or `dict` can be type hinted instead of `typing.List` or `typing.Dict`. Also use `collections.abc` instead of `typing` analogues. Interface generator still generates code using `typing` but it will be changed in the future.
1 parent 7a85f12 commit 5acc62f

37 files changed

+249
-323
lines changed

docs/asyncio_api.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ Classes
6868
either raise an ``"error"`` (default), ``"ignore"`` the property
6969
or ``"reuse"`` the D-Bus name for the member.
7070
:return: dictionary of properties
71-
:rtype: Dict[str, Any]
71+
:rtype: dict[str, Any]
7272

7373
.. py:attribute:: properties_changed
74-
:type: Tuple[str, Dict[str, Tuple[str, Any]], List[str]]
74+
:type: tuple[str, dict[str, tuple[str, Any]], list[str]]
7575

7676
Signal when one of the objects properties changes.
7777

@@ -83,11 +83,11 @@ Classes
8383
Interface name : str
8484
Name of the interface where property changed
8585

86-
Changed properties : Dict[str, Tuple[str, Any]]
86+
Changed properties : dict[str, tuple[str, Any]]
8787
Dictionary there keys are names of properties changed and
8888
values are variants of new value.
8989

90-
Invalidated properties : List[str]
90+
Invalidated properties : list[str]
9191
List of property names changed but no new value had been provided
9292

9393
.. py:method:: _proxify(bus, service_name, object_path)
@@ -199,12 +199,12 @@ Classes
199199
Triple nested dictionary that contains all the objects
200200
paths with their properties values.
201201

202-
Dict[ObjectPath, Dict[InterfaceName, Dict[PropertyName, PropertyValue]]]
202+
dict[ObjectPath, dict[InterfaceName, dict[PropertyName, PropertyValue]]]
203203

204-
:rtype: Dict[str, Dict[str, Dict[str, Any]]]
204+
:rtype: dict[str, dict[str, dict[str, Any]]]
205205

206206
.. py:attribute:: interfaces_added
207-
:type: Tuple[str, Dict[str, Dict[str, Any]]]
207+
:type: tuple[str, dict[str, dict[str, Any]]]
208208

209209
Signal when a new object is added or and existing object
210210
gains a new interface.
@@ -217,11 +217,11 @@ Classes
217217
Object path : str
218218
Path to object that was added or modified.
219219

220-
Object interfaces and properties : Dict[str, Dict[str, Any]]]
221-
Dict[InterfaceName, Dict[PropertyName, PropertyValue]]
220+
Object interfaces and properties : dict[str, dict[str, Any]]]
221+
dict[InterfaceName, dict[PropertyName, PropertyValue]]
222222

223223
.. py:attribute:: interfaces_removed
224-
:type: Tuple[str, List[str]]
224+
:type: tuple[str, list[str]]
225225

226226
Signal when existing object or and interface of
227227
existing object is removed.
@@ -234,7 +234,7 @@ Classes
234234
Object path : str
235235
Path to object that was removed or modified.
236236

237-
Interfaces list : List[str]
237+
Interfaces list : list[str]
238238
Interfaces names that were removed.
239239

240240
.. py:method:: export_with_manager(object_path, object_to_export, bus)

docs/asyncio_quick.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Example: ::
5050

5151
# Signal with a list of strings
5252
@dbus_signal_async('as')
53-
def str_signal(self) -> List[str]:
53+
def str_signal(self) -> list[str]:
5454
raise NotImplementedError
5555

5656
Initiating proxy
@@ -342,7 +342,7 @@ Example: ::
342342
):
343343

344344
@dbus_method_async('as', 's')
345-
async def join_str(self, str_array: List[str]) -> str:
345+
async def join_str(self, str_array: list[str]) -> str:
346346
return ''.join(str_array)
347347

348348

docs/autodoc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ stub function.
5151
.. code-block:: python
5252
5353
@dbus_property_async('as')
54-
def features(self) -> List[str]:
54+
def features(self) -> list[str]:
5555
"""List of D-Bus daemon features.
5656
5757
Features include:

docs/sync_api.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Classes
7272
either raise an ``"error"`` (default), ``"ignore"`` the property
7373
or ``"reuse"`` the D-Bus name for the member.
7474
:return: dictionary of properties
75-
:rtype: Dict[str, Any]
75+
:rtype: dict[str, Any]
7676

7777
Example: ::
7878

@@ -91,12 +91,12 @@ Classes
9191

9292
# Method that does not take any arguments and returns a list of str
9393
@dbus_method()
94-
def get_capabilities(self) -> List[str]:
94+
def get_capabilities(self) -> list[str]:
9595
raise NotImplementedError
9696

9797
# Method that takes a dict of {str: str} and returns an int
9898
@dbus_method('a{ss}')
99-
def count_entries(self, a_dict: Dict[str, str]) -> int:
99+
def count_entries(self, a_dict: dict[str, str]) -> int:
100100
raise NotImplementedError
101101

102102
# Read only property of int
@@ -124,9 +124,9 @@ Classes
124124
Triple nested dictionary that contains all the objects
125125
paths with their properties values.
126126

127-
Dict[ObjectPath, Dict[InterfaceName, Dict[PropertyName, PropertyValue]]]
127+
dict[ObjectPath, dict[InterfaceName, dict[PropertyName, PropertyValue]]]
128128

129-
:rtype: Dict[str, Dict[str, Dict[str, Any]]]
129+
:rtype: dict[str, dict[str, dict[str, Any]]]
130130

131131
Decorators
132132
+++++++++++++++
@@ -168,12 +168,12 @@ Decorators
168168

169169
# Method that does not take any arguments and returns a list of str
170170
@dbus_method()
171-
def get_capabilities(self) -> List[str]:
171+
def get_capabilities(self) -> list[str]:
172172
raise NotImplementedError
173173

174174
# Method that takes a dict of {str: str} and returns an int
175175
@dbus_method('a{ss}')
176-
def count_entries(self, a_dict: Dict[str, str]) -> int:
176+
def count_entries(self, a_dict: dict[str, str]) -> int:
177177
raise NotImplementedError
178178

179179
Calling methods example::

docs/sync_quick.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Example: ::
157157
):
158158

159159
@dbus_method('as')
160-
def test_method(self, str_array: List[str]) -> None:
160+
def test_method(self, str_array: list[str]) -> None:
161161
raise NotImplementedError
162162

163163

docs/unittest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Python-sdbus provides several utilities to enable unit testing.
3030
"""Uppercase the input"""
3131
return string.upper()
3232

33-
def initialize_object() -> Tuple[TestInterface, TestInterface]:
33+
def initialize_object() -> tuple[TestInterface, TestInterface]:
3434
test_object = TestInterface()
3535
test_object.export_to_dbus('/')
3636

@@ -74,7 +74,7 @@ Python-sdbus provides several utilities to enable unit testing.
7474
The object returned by context manager has following attributes:
7575

7676
.. py:attribute:: output
77-
:type: List[Any]
77+
:type: list[Any]
7878

7979
List of captured data.
8080

docs/utils.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Available under ``sdbus.utils.parse`` subpackage.
2121
:param str on_unknown_member: If an unknown D-Bus property was encountered
2222
either raise an ``"error"`` (default), ``"ignore"`` the property
2323
or ``"reuse"`` the D-Bus name for the member.
24-
:rtype: Dict[str, Any]
24+
:rtype: dict[str, Any]
2525
:returns: Dictionary of changed properties with keys translated to python
2626
names. Invalidated properties will have value of None.
2727

@@ -42,7 +42,7 @@ Available under ``sdbus.utils.parse`` subpackage.
4242
:param str on_unknown_member: If an unknown D-Bus property was encountered
4343
either raise an ``"error"`` (default), ``"ignore"`` the property
4444
or ``"reuse"`` the D-Bus name for the member.
45-
:rtype: Tuple[str, Optional[Type[DbusInterfaceBaseAsync]], Dict[str, Any]]
45+
:rtype: tuple[str, Optional[type[DbusInterfaceBaseAsync]], dict[str, Any]]
4646
:returns: Path of new added object, object's class (or ``None``) and dictionary
4747
of python translated members and their values.
4848

@@ -60,7 +60,7 @@ Available under ``sdbus.utils.parse`` subpackage.
6060
:param str on_unknown_member: If an unknown D-Bus interface was encountered
6161
either raise an ``"error"`` (default) or return ``"none"`` instead
6262
of interface class.
63-
:rtype: Tuple[str, Optional[Type[DbusInterfaceBaseAsync]]]
63+
:rtype: tuple[str, Optional[type[DbusInterfaceBaseAsync]]]
6464
:returns: Path of removed object and object's class (or ``None``).
6565

6666
.. py:function:: parse_get_managed_objects(interfaces, managed_objects_data, on_unknown_interface='error', on_unknown_member='error')
@@ -80,7 +80,7 @@ Available under ``sdbus.utils.parse`` subpackage.
8080
:param str on_unknown_member: If an unknown D-Bus property was encountered
8181
either raise an ``"error"`` (default), ``"ignore"`` the property
8282
or ``"reuse"`` the D-Bus name for the member.
83-
:rtype: Dict[str, Tuple[Optional[Type[DbusInterfaceBaseAsync], Dict[str, Any]]]]
83+
:rtype: dict[str, tuple[Optional[type[DbusInterfaceBaseAsync], dict[str, Any]]]]
8484
:returns: Dictionary where keys are paths and values are tuples of managed objects classes and their properties data.
8585

8686
*New in version 0.12.0.*

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
from os import environ
2323
from subprocess import DEVNULL, PIPE
2424
from subprocess import run as subprocess_run
25-
from typing import List, Optional, Tuple
25+
from typing import Optional
2626

2727
from setuptools import Extension, setup
2828

29-
c_macros: List[Tuple[str, Optional[str]]] = []
29+
c_macros: list[tuple[str, Optional[str]]] = []
3030

3131

3232
def get_libsystemd_version() -> int:
@@ -55,7 +55,7 @@ def get_libsystemd_version() -> int:
5555
c_macros.append(('LIBSYSTEMD_NO_OPEN_USER_MACHINE', None))
5656

5757

58-
def get_link_arguments() -> List[str]:
58+
def get_link_arguments() -> list[str]:
5959
process = subprocess_run(
6060
args=('pkg-config', '--libs-only-l', 'libsystemd'),
6161
stderr=DEVNULL,
@@ -68,7 +68,7 @@ def get_link_arguments() -> List[str]:
6868
return result_str.rstrip(' \n').split(' ')
6969

7070

71-
link_arguments: List[str] = get_link_arguments()
71+
link_arguments: list[str] = get_link_arguments()
7272

7373
if environ.get('PYTHON_SDBUS_USE_STATIC_LINK'):
7474
# Link statically against libsystemd and libcap
@@ -77,7 +77,7 @@ def get_link_arguments() -> List[str]:
7777

7878
link_arguments.append('-flto')
7979

80-
compile_arguments: List[str] = ['-flto']
80+
compile_arguments: list[str] = ['-flto']
8181

8282
use_limited_api = False
8383

src/sdbus/__main__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333

3434
if TYPE_CHECKING:
35-
from typing import Dict, List, Optional
35+
from typing import Optional
3636

3737
from .interface_generator import DbusInterfaceIntrospection
3838

@@ -41,22 +41,22 @@
4141
class RenameMember:
4242
new_name: Optional[str] = None
4343
current_arg: Optional[str] = None
44-
arg_renames: Dict[str, str] = field(default_factory=dict)
44+
arg_renames: dict[str, str] = field(default_factory=dict)
4545

4646

4747
@dataclass
4848
class RenameInterface:
4949
new_name: Optional[str] = None
5050
current_member: Optional[RenameMember] = None
51-
methods: Dict[str, RenameMember] = field(default_factory=dict)
52-
properties: Dict[str, RenameMember] = field(default_factory=dict)
53-
signals: Dict[str, RenameMember] = field(default_factory=dict)
51+
methods: dict[str, RenameMember] = field(default_factory=dict)
52+
properties: dict[str, RenameMember] = field(default_factory=dict)
53+
signals: dict[str, RenameMember] = field(default_factory=dict)
5454

5555

5656
@dataclass
5757
class RenameRoot:
5858
current_interface: Optional[RenameInterface] = None
59-
interfaces: Dict[str, RenameInterface] = field(default_factory=dict)
59+
interfaces: dict[str, RenameInterface] = field(default_factory=dict)
6060

6161

6262
rename_root = RenameRoot()
@@ -96,7 +96,7 @@ def rename_members(
9696

9797

9898
def rename_interfaces(
99-
interfaces: List[DbusInterfaceIntrospection]
99+
interfaces: list[DbusInterfaceIntrospection]
100100
) -> None:
101101
for interface in interfaces:
102102
dbus_interface_name = interface.interface_name
@@ -112,7 +112,7 @@ def rename_interfaces(
112112

113113
def run_gen_from_connection(
114114
connection_name: str,
115-
object_paths: List[str],
115+
object_paths: list[str],
116116
system: bool,
117117
imports_header: bool,
118118
do_async: bool,
@@ -127,7 +127,7 @@ def run_gen_from_connection(
127127
from .sd_bus_internals import sd_bus_open_system
128128
set_default_bus(sd_bus_open_system())
129129

130-
interfaces: List[DbusInterfaceIntrospection] = []
130+
interfaces: list[DbusInterfaceIntrospection] = []
131131
for object_path in object_paths:
132132
connection = DbusInterfaceCommon(connection_name, object_path)
133133
itrospection = connection.dbus_introspect()
@@ -145,11 +145,11 @@ def run_gen_from_connection(
145145

146146

147147
def run_gen_from_file(
148-
filenames: List[str],
148+
filenames: list[str],
149149
imports_header: bool,
150150
do_async: bool,
151151
) -> None:
152-
interfaces: List[DbusInterfaceIntrospection] = []
152+
interfaces: list[DbusInterfaceIntrospection] = []
153153

154154
for file in filenames:
155155
interfaces.extend(interfaces_from_file(file))
@@ -308,7 +308,7 @@ def __call__(
308308
)
309309

310310

311-
def generator_main(args: Optional[List[str]] = None) -> None:
311+
def generator_main(args: Optional[list[str]] = None) -> None:
312312

313313
main_arg_parser = ArgumentParser(
314314
prog="sdbus",

src/sdbus/autodoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .dbus_proxy_async_signal import DbusSignalAsync
2929

3030
if TYPE_CHECKING:
31-
from typing import Any, Dict
31+
from typing import Any
3232

3333
from sphinx.application import Sphinx
3434

@@ -129,7 +129,7 @@ def add_content(self,
129129
super().add_content(*args, **kwargs)
130130

131131

132-
def setup(app: Sphinx) -> Dict[str, bool]:
132+
def setup(app: Sphinx) -> dict[str, bool]:
133133
app.setup_extension('sphinx.ext.autodoc')
134134
app.add_autodocumenter(DbusMethodDocumenter)
135135
app.add_autodocumenter(DbusPropertyDocumenter)

0 commit comments

Comments
 (0)