Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
ci:
autofix_commit_msg: "Apply pre-commit auto fixes"
autoupdate_commit_msg: "Auto-update pre-commit hooks"
skip: [mypy]

repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[tool.mypy]
python_version = "3.10"
strict = true
check_untyped_defs = true
show_error_codes = true
Expand Down
18 changes: 10 additions & 8 deletions serialx/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ class StopBits(Enum):
TWO = 2


class Parity(Enum):
class Parity(str, Enum):
"""Parity configuration."""

NONE = None
ODD = 1
EVEN = 2
MARK = 3
SPACE = 4
NONE = "N"
ODD = "O"
EVEN = "E"
MARK = "M"
SPACE = "S"


class PinState(Enum):
Expand Down Expand Up @@ -300,7 +300,7 @@ def __init__(
path: str | Path | None = None,
baudrate: int = 9600,
*,
parity: Parity | None = Parity.NONE,
parity: Parity | str | None = Parity.NONE,
stopbits: StopBits | int | float = StopBits.ONE,
xonxoff: bool = False,
rtscts: bool = False,
Expand All @@ -327,7 +327,9 @@ def __init__(
if not isinstance(stopbits, StopBits):
stopbits = StopBits(stopbits)

if not isinstance(parity, Parity):
if parity is None:
parity = Parity.NONE
elif not isinstance(parity, Parity):
parity = Parity(parity)

self._path = path
Expand Down
8 changes: 7 additions & 1 deletion tests/test_pyserial_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
allow_module_level=True,
)

from serialx import Serial, SerialPortInfo
from serialx import Parity, Serial, SerialPortInfo
from serialx.tools.list_ports import comports, grep
from serialx.tools.list_ports_common import ListPortInfo
from tests.common import SerialPair
Expand Down Expand Up @@ -82,6 +82,12 @@ def test_compat_timeout_setter(serial_pair: SerialPair) -> None:
assert s.read_timeout == 0.5


def test_compat_parity_none(serial_pair: SerialPair) -> None:
"""Test that `parity=None` is accepted and maps to `Parity.NONE`."""
with Serial.from_url(serial_pair.left, baudrate=115200, parity=None) as s:
assert s.parity is Parity.NONE


def test_compat_baudrate_setter(serial_pair: SerialPair) -> None:
"""Test that the deprecated .baudrate setter reconfigures the port."""
with Serial.from_url(serial_pair.left, baudrate=9600) as s:
Expand Down
Loading