Skip to content

Commit dddc7c4

Browse files
committed
pyupgrade to Python 3.9+
1 parent 07f306a commit dddc7c4

24 files changed

Lines changed: 42 additions & 63 deletions

alsa_midi/address.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
from collections import namedtuple
3-
from typing import TYPE_CHECKING, Any, Tuple, Union, overload
2+
from typing import TYPE_CHECKING, Any, Union, overload
43

54
from ._ffi import alsa, ffi
65
from .util import _check_alsa_error
@@ -10,7 +9,7 @@
109
from .port import Port, PortInfo
1110

1211

13-
AddressType = Union['Address', 'Port', 'PortInfo', Tuple[int, int]]
12+
AddressType = Union['Address', 'Port', 'PortInfo', tuple[int, int]]
1413

1514

1615
class Address(namedtuple("Address", "client_id port_id")):
@@ -79,7 +78,7 @@ def __new__(cls,
7978
return tuple.__new__(cls, tple)
8079

8180
@staticmethod
82-
def _parse(arg: str) -> Tuple[int, int]:
81+
def _parse(arg: str) -> tuple[int, int]:
8382
addr_p = ffi.new("snd_seq_addr_t *")
8483
result = alsa.snd_seq_parse_address(ffi.NULL, addr_p, arg.encode())
8584
_check_alsa_error(result)

alsa_midi/client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
import asyncio
32
import errno
43
import select
54
import time
5+
from collections.abc import MutableMapping
66
from dataclasses import dataclass, field
77
from enum import IntEnum, IntFlag
88
from functools import partial
9-
from typing import (Any, Callable, List, MutableMapping, NewType, Optional, Set, Tuple, Union,
10-
overload)
9+
from typing import Any, Callable, NewType, Optional, Union, overload
1110
from weakref import WeakValueDictionary
1211

1312
from ._ffi import alsa, ffi
@@ -21,7 +20,7 @@
2120
from .util import _check_alsa_error
2221

2322
_snd_seq_t = NewType("_snd_seq_t", object)
24-
_snd_seq_t_p = NewType("_snd_seq_t_p", Tuple[_snd_seq_t])
23+
_snd_seq_t_p = NewType("_snd_seq_t_p", tuple[_snd_seq_t])
2524
_snd_midi_event_t = NewType("_snd_midi_event_t", object)
2625

2726

@@ -90,7 +89,7 @@ class ClientInfo:
9089
pid: Optional[int] = None
9190
num_ports: int = 0
9291
event_lost: int = 0
93-
event_filter: Optional[Set[EventType]] = None
92+
event_filter: Optional[set[EventType]] = None
9493

9594
@classmethod
9695
def _from_alsa(cls, info: _snd_seq_client_info_t):
@@ -661,7 +660,7 @@ def drop_output_buffer(self):
661660
err = alsa.snd_seq_drop_output_buffer(self.handle)
662661
_check_alsa_error(err)
663662

664-
def _event_input(self, prefer_bytes: bool = False) -> Tuple[int, Optional[Event]]:
663+
def _event_input(self, prefer_bytes: bool = False) -> tuple[int, Optional[Event]]:
665664
buf = ffi.new("snd_seq_event_t**", ffi.NULL)
666665
result = alsa.snd_seq_event_input(self.handle, buf)
667666
if result < 0:
@@ -730,7 +729,7 @@ def _prepare_event(self,
730729
queue: Union['Queue', int] = None,
731730
port: Union['Port', int] = None,
732731
dest: AddressType = None,
733-
remainder: Optional[Any] = None) -> Tuple[_snd_seq_event_t, Any]:
732+
remainder: Optional[Any] = None) -> tuple[_snd_seq_event_t, Any]:
734733
"""Prepare ALSA :alsa:`snd_seq_event_t` for given `event` object for output.
735734
736735
For :class:`alsa_midi.MidiBytesEvent` may need to be called more than
@@ -780,7 +779,7 @@ def _event_output(self,
780779
queue: Union['Queue', int] = None,
781780
port: Union['Port', int] = None,
782781
dest: AddressType = None,
783-
remainder: Optional[Any] = None) -> Tuple[int, Any]:
782+
remainder: Optional[Any] = None) -> tuple[int, Any]:
784783
alsa_event, remainder = self._prepare_event(event,
785784
queue=queue, port=port, dest=dest,
786785
remainder=remainder)
@@ -864,7 +863,7 @@ def _event_output_direct(self,
864863
queue: Union['Queue', int] = None,
865864
port: Union['Port', int] = None,
866865
dest: AddressType = None,
867-
remainder: Optional[Any] = None) -> Tuple[int, Any]:
866+
remainder: Optional[Any] = None) -> tuple[int, Any]:
868867
alsa_event, remainder = self._prepare_event(event,
869868
queue=queue, port=port, dest=dest,
870869
remainder=remainder)
@@ -1114,7 +1113,7 @@ def list_ports(self, *,
11141113
include_no_export: bool = True,
11151114
only_connectable: bool = True,
11161115
sort: Union[bool, Callable[[PortInfo], Any]] = True,
1117-
) -> List[PortInfo]:
1116+
) -> list[PortInfo]:
11181117
"""More friendly interface to list available ports.
11191118
11201119
Queries ALSA for all clients and ports and returns those matching the selected criteria.
@@ -1327,7 +1326,7 @@ def query_port_subscribers(self,
13271326
def list_port_subscribers(self,
13281327
port: AddressType,
13291328
type: Optional[SubscriptionQueryType] = None,
1330-
) -> List[SubscriptionQuery]:
1329+
) -> list[SubscriptionQuery]:
13311330
"""Lists subscribers accessing a port.
13321331
13331332
Wraps :alsa:`snd_seq_query_port_subscribers`.

alsa_midi/event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
1+
from collections.abc import Iterable
22
from enum import IntEnum, IntFlag
33
from functools import total_ordering
4-
from typing import TYPE_CHECKING, Any, Iterable, NewType, Optional, Union
4+
from typing import TYPE_CHECKING, Any, NewType, Optional, Union
55

66
from ._ffi import alsa, ffi
77
from .address import Address, AddressType

alsa_midi/mido_backend.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import queue
1414
import sys
1515
import threading
16-
from typing import Any, Callable, List, MutableMapping, Optional
16+
from collections.abc import MutableMapping
17+
from typing import Any, Callable, Optional
1718
from weakref import WeakValueDictionary
1819

1920
from mido.messages import Message
@@ -92,7 +93,7 @@ def get_devices(*args, **kwargs):
9293
return client.get_devices(*args, **kwargs)
9394

9495

95-
def _find_port(ports: List[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo:
96+
def _find_port(ports: list[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo:
9697
try:
9798
addr = alsa_midi.Address(name)
9899
except (ValueError, alsa_midi.exceptions.ALSAError):
@@ -104,7 +105,7 @@ def _find_port(ports: List[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo
104105
if addr == alsa_midi.Address(port):
105106
return port
106107
else:
107-
raise IOError(f"unknown port {name!r}")
108+
raise OSError(f"unknown port {name!r}")
108109

109110
# check for exact match with name from get_devices()
110111
for port in ports:
@@ -128,10 +129,10 @@ def _find_port(ports: List[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo
128129
if name == port.name:
129130
return port
130131

131-
raise IOError(f"unknown port {name!r}")
132+
raise OSError(f"unknown port {name!r}")
132133

133134

134-
class PortCommon(object):
135+
class PortCommon:
135136
_last_num = 0
136137
_name_prefix = "inout"
137138
_caps = alsa_midi.PortCaps.READ | alsa_midi.PortCaps.WRITE
@@ -182,7 +183,7 @@ def _open(self, virtual=False, **kwargs):
182183
ports = client.client.list_ports(input=self._for_input, output=self._for_output)
183184

184185
if not ports:
185-
raise IOError('no ports available')
186+
raise OSError('no ports available')
186187

187188
if self.name is None:
188189
dest_port = ports[0]
@@ -200,9 +201,9 @@ def _open(self, virtual=False, **kwargs):
200201
self._dest_port = dest_port
201202

202203
api = 'seq'
203-
self._device_type = 'AlsaMidi/{}'.format(api)
204+
self._device_type = f'AlsaMidi/{api}'
204205
if virtual:
205-
self._device_type = 'virtual {}'.format(self._device_type)
206+
self._device_type = f'virtual {self._device_type}'
206207

207208
client.ports[self._port.port_id] = self
208209

alsa_midi/port.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
from dataclasses import InitVar, dataclass, field
32
from enum import IntFlag
4-
from typing import TYPE_CHECKING, Any, Callable, List, NewType, Optional
3+
from typing import TYPE_CHECKING, Any, Callable, NewType, Optional
54

65
from ._ffi import alsa, ffi
76
from .address import Address, AddressType
@@ -176,7 +175,7 @@ def set_info(self, info: 'PortInfo'):
176175
raise StateError("Already closed")
177176
return self.client.set_port_info(self, info)
178177

179-
def list_subscribers(self, type: 'SubscriptionQueryType' = None) -> List['SubscriptionQuery']:
178+
def list_subscribers(self, type: 'SubscriptionQueryType' = None) -> list['SubscriptionQuery']:
180179
"""Lists subscribers accessing a port.
181180
182181
Wraps :alsa:`snd_seq_query_port_subscribers`.
@@ -286,7 +285,7 @@ def _to_alsa(self) -> _snd_seq_port_info_t:
286285
return info
287286

288287

289-
def get_port_info_sort_key(preferred_types: List[PortType] = []
288+
def get_port_info_sort_key(preferred_types: list[PortType] = []
290289
) -> Callable[[PortInfo], Any]:
291290
"""Return a :class:`PortInfo` sorting key function for given type
292291
preference."""

alsa_midi/queue.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from dataclasses import dataclass, field
32
from enum import IntEnum
43
from typing import TYPE_CHECKING, NamedTuple, NewType, Optional, Union

alsa_midi/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from ._ffi import alsa, ffi
32
from .exceptions import ALSAError
43

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import os
32

43
from setuptools import setup

tests/conftest.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
21
import asyncio
32
import os
43
import re
54
import subprocess
65
import sys
76
from statistics import mean
8-
from typing import Dict, List, Optional, Tuple
7+
from typing import Optional
98

109
import pytest
1110
import pytest_asyncio
@@ -16,8 +15,8 @@ class AlsaPortState:
1615
port_id: int
1716
name: str
1817
flags: str
19-
connected_from: List[Tuple[int, int]]
20-
connected_to: List[Tuple[int, int]]
18+
connected_from: list[tuple[int, int]]
19+
connected_to: list[tuple[int, int]]
2120

2221
def __init__(self, client_id, port_id, name, flags):
2322
self.client_id = client_id
@@ -44,8 +43,8 @@ class AlsaClientState:
4443
name: str
4544
type: str
4645
version: Optional[str]
47-
ports: Dict[int, AlsaPortState]
48-
queues: Dict[int, 'AlsaQueueState']
46+
ports: dict[int, AlsaPortState]
47+
queues: dict[int, 'AlsaQueueState']
4948

5049
def __init__(self, client_id, name, client_type, midi_version):
5150
self.client_id = client_id
@@ -80,7 +79,7 @@ class AlsaQueueState:
8079
timer_ppq: int
8180
current_tempo: int
8281
current_bpm: int
83-
current_time: Tuple[int, int]
82+
current_time: tuple[int, int]
8483
current_tick: int
8584

8685
def __init__(self, lines):
@@ -138,7 +137,7 @@ def __str__(self):
138137
PROC_CONN_FROM_LINE_RE = re.compile(r'\s+Connected From:\s*(\S.*)$')
139138

140139

141-
def parse_port_list(string: str) -> List[Tuple[int, int]]:
140+
def parse_port_list(string: str) -> list[tuple[int, int]]:
142141
port_list = [p.strip() for p in string.split(",")]
143142
port_list = [p.split("[", 1)[0] for p in port_list]
144143
port_list = [p.split(":", 1) for p in port_list]
@@ -147,9 +146,9 @@ def parse_port_list(string: str) -> List[Tuple[int, int]]:
147146

148147

149148
class AlsaSequencerState:
150-
clients: Dict[int, AlsaClientState]
151-
ports: Dict[Tuple[int, int], AlsaPortState]
152-
queues: Dict[int, AlsaQueueState]
149+
clients: dict[int, AlsaClientState]
150+
ports: dict[tuple[int, int], AlsaPortState]
151+
queues: dict[int, AlsaQueueState]
153152
max_clients: int
154153
cur_clients: int
155154

@@ -174,7 +173,7 @@ def load(self):
174173
self.queues = {}
175174

176175
print("clients:")
177-
with open("/proc/asound/seq/clients", "r") as proc_f:
176+
with open("/proc/asound/seq/clients") as proc_f:
178177
client = None
179178
port = None
180179
for line in proc_f:
@@ -215,7 +214,7 @@ def load(self):
215214
continue
216215

217216
print("queues:")
218-
with open("/proc/asound/seq/queues", "r") as proc_f:
217+
with open("/proc/asound/seq/queues") as proc_f:
219218
queues = []
220219
queue_lines = []
221220
for line in proc_f:
@@ -247,10 +246,10 @@ def alsa_seq_state():
247246
if not alsa_seq_present:
248247
try:
249248
# try triggering snd-seq module load
250-
with open("/dev/snd/seq", "r"):
249+
with open("/dev/snd/seq"):
251250
pass
252251
alsa_seq_present = os.path.exists("/proc/asound/seq/clients")
253-
except IOError:
252+
except OSError:
254253
pass
255254

256255

@@ -328,7 +327,7 @@ def aseqdump():
328327

329328
class Aseqdump:
330329
process: Optional[subprocess.Popen]
331-
output: List[Tuple[Address, str]]
330+
output: list[tuple[Address, str]]
332331
port: Address
333332

334333
def __init__(self, process: subprocess.Popen):

tests/test_address.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import errno
32

43
import pytest

0 commit comments

Comments
 (0)