File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- ci :
2- autofix_commit_msg : " Apply pre-commit auto fixes"
3- autoupdate_commit_msg : " Auto-update pre-commit hooks"
4- skip : [mypy]
5-
61repos :
72 - repo : https://github.com/codespell-project/codespell
83 rev : v2.4.1
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ asyncio_mode = "auto"
7171asyncio_default_fixture_loop_scope = " function"
7272
7373[tool .mypy ]
74+ python_version = " 3.10"
7475strict = true
7576check_untyped_defs = true
7677show_error_codes = true
Original file line number Diff line number Diff line change @@ -184,14 +184,14 @@ class StopBits(Enum):
184184 TWO = 2
185185
186186
187- class Parity (Enum ):
187+ class Parity (str , Enum ):
188188 """Parity configuration."""
189189
190- NONE = None
191- ODD = 1
192- EVEN = 2
193- MARK = 3
194- SPACE = 4
190+ NONE = "N"
191+ ODD = "O"
192+ EVEN = "E"
193+ MARK = "M"
194+ SPACE = "S"
195195
196196
197197class PinState (Enum ):
@@ -300,7 +300,7 @@ def __init__(
300300 path : str | Path | None = None ,
301301 baudrate : int = 9600 ,
302302 * ,
303- parity : Parity | None = Parity .NONE ,
303+ parity : Parity | str | None = Parity .NONE ,
304304 stopbits : StopBits | int | float = StopBits .ONE ,
305305 xonxoff : bool = False ,
306306 rtscts : bool = False ,
@@ -327,7 +327,9 @@ def __init__(
327327 if not isinstance (stopbits , StopBits ):
328328 stopbits = StopBits (stopbits )
329329
330- if not isinstance (parity , Parity ):
330+ if parity is None :
331+ parity = Parity .NONE
332+ elif not isinstance (parity , Parity ):
331333 parity = Parity (parity )
332334
333335 self ._path = path
Original file line number Diff line number Diff line change 1111 allow_module_level = True ,
1212 )
1313
14- from serialx import Serial , SerialPortInfo
14+ from serialx import Parity , Serial , SerialPortInfo
1515from serialx .tools .list_ports import comports , grep
1616from serialx .tools .list_ports_common import ListPortInfo
1717from tests .common import SerialPair
@@ -82,6 +82,12 @@ def test_compat_timeout_setter(serial_pair: SerialPair) -> None:
8282 assert s .read_timeout == 0.5
8383
8484
85+ def test_compat_parity_none (serial_pair : SerialPair ) -> None :
86+ """Test that `parity=None` is accepted and maps to `Parity.NONE`."""
87+ with Serial .from_url (serial_pair .left , baudrate = 115200 , parity = None ) as s :
88+ assert s .parity is Parity .NONE
89+
90+
8591def test_compat_baudrate_setter (serial_pair : SerialPair ) -> None :
8692 """Test that the deprecated .baudrate setter reconfigures the port."""
8793 with Serial .from_url (serial_pair .left , baudrate = 9600 ) as s :
You can’t perform that action at this time.
0 commit comments