Skip to content

Commit a1d3cf6

Browse files
replace kwargs with keyword-only arguments
1 parent 1ab4cf5 commit a1d3cf6

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/pylibftdi/device.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
cast,
2525
create_string_buffer,
2626
)
27-
from typing import Any, no_type_check
27+
from typing import no_type_check
2828

2929
from pylibftdi._base import FtdiError
3030
from pylibftdi.driver import (
@@ -128,7 +128,14 @@ def __init__(
128128
encoding: str = "latin1",
129129
interface_select: int | None = None,
130130
device_index: int = 0,
131-
**kwargs: Any,
131+
*,
132+
auto_detach: bool | None = None,
133+
lazy_open: bool | None = None,
134+
chunk_size: int | None = None,
135+
index: int | None = None,
136+
vid: int | None = None,
137+
pid: int | None = None,
138+
driver: Driver | None = None,
132139
) -> None:
133140
"""
134141
Device([device_id[, mode, [OPTIONS ...]]) -> Device instance
@@ -181,14 +188,16 @@ def __init__(
181188
"""
182189
self._opened = False
183190

184-
# Some behavioural attributes are extracted from kwargs and override
185-
# existing attribute defaults. This allows subclassing to easily
186-
# change these.
187-
for param in ["auto_detach", "lazy_open", "chunk_size"]:
188-
if param in kwargs:
189-
setattr(self, param, kwargs.pop(param))
191+
# These args allow overriding default class attributes, which can
192+
# also be overridden in subclasses.
193+
if auto_detach is not None:
194+
self.auto_detach = auto_detach
195+
if lazy_open is not None:
196+
self.lazy_open = lazy_open
197+
if chunk_size is not None:
198+
self.chunk_size = chunk_size
190199

191-
self.driver: Driver = Driver(**kwargs)
200+
self.driver = Driver() if driver is None else driver
192201
self.fdll = self.driver.fdll
193202
# device_id is an optional serial number of the requested device.
194203
self.device_id = device_id
@@ -214,9 +223,9 @@ def __init__(
214223
self.device_index = device_index
215224
# list_index (from parameter `index`) is an optional integer index
216225
# into list_devices() entries.
217-
self.list_index = kwargs.pop("index", None)
218-
self.vid = kwargs.pop("vid", None)
219-
self.pid = kwargs.pop("pid", None)
226+
self.list_index = index
227+
self.vid = vid
228+
self.pid = pid
220229

221230
# lazy_open tells us not to open immediately.
222231
if not self.lazy_open:

src/pylibftdi/driver.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ class Driver:
9696
"libusb": ["usb-1.0", "libusb-1.0"],
9797
}
9898

99-
def __init__(
100-
self, libftdi_search: str | list[str] | None = None, **kwargs: dict[str, Any]
101-
) -> None:
99+
def __init__(self, libftdi_search: str | list[str] | None = None) -> None:
102100
"""
103101
:param libftdi_search: force a particular version of libftdi to be used
104102
can specify either library name(s) or path(s)

0 commit comments

Comments
 (0)