2424 cast ,
2525 create_string_buffer ,
2626)
27- from typing import Any , no_type_check
27+ from typing import no_type_check
2828
2929from pylibftdi ._base import FtdiError
3030from 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 :
0 commit comments