From 51d5b1bd0bfb44c53b960d32613be09818f93383 Mon Sep 17 00:00:00 2001 From: Gert van Dijk Date: Sat, 11 Feb 2023 16:47:59 +0100 Subject: [PATCH] Suppress Ruff's (unsupported) Structural Pattern Matching syntax errors Work-around with suppression of syntax error printed has been added in version 0.0.245. - https://github.com/charliermarsh/ruff/pull/2697 - https://github.com/charliermarsh/ruff/pull/2505#issuecomment-1419119921 --- pyproject.toml | 2 +- run-all-linters | 4 +--- src/purepythonmilter/api/logger.py | 2 +- src/purepythonmilter/examples/append_header_ip/__main__.py | 2 +- src/purepythonmilter/protocol/commands.py | 2 +- src/purepythonmilter/server/session.py | 2 +- tests/protocol/test_commands.py | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7959f56..190cf29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ development = [ "pytest", "pyupgrade", "reuse", - "ruff", + "ruff>=0.0.245", "setuptools-scm[toml]>=6.2", "twine", "validate-pyproject[all]", diff --git a/run-all-linters b/run-all-linters index 2f56971..53993db 100755 --- a/run-all-linters +++ b/run-all-linters @@ -25,9 +25,7 @@ echo "ruff..." "$PYTHON" -m ruff --diff "${PYTHON_SOURCES_DIRS[@]}" || \ (echo "Run 'ruff --fix ${PYTHON_SOURCES_DIRS[*]}' to fix auto-fixable."; exit 1) # Also lint for non-auto-fixables - requires a separate invocation apparently. -# Disabled for now due to missing support for structural pattern matching: -# https://github.com/charliermarsh/ruff/issues/282 -# "$PYTHON" -m ruff --show-source ${PYTHON_SOURCES_DIRS} +"$PYTHON" -m ruff "${PYTHON_SOURCES_DIRS[@]}" echo "OK!" # Pyupgrade will never provide a check-mode in itself unfortunately. 😥 diff --git a/src/purepythonmilter/api/logger.py b/src/purepythonmilter/api/logger.py index 7b5b0d8..c637a00 100644 --- a/src/purepythonmilter/api/logger.py +++ b/src/purepythonmilter/api/logger.py @@ -42,7 +42,7 @@ def process(self, msg: Any, kwargs: LoggingKwargs) -> tuple[Any, LoggingKwargs]: assert hasattr(self, "extra") and self.extra is not None # If we get instantiated with a connection ID context, let's use that. # Otherwise, try again at process time to obtain it. - match self.extra.get("connection_id"): + match self.extra.get("connection_id"): # noqa: E999 case models.MilterServerConnectionID() as connection_id: connection_id_short = connection_id.short case _: diff --git a/src/purepythonmilter/examples/append_header_ip/__main__.py b/src/purepythonmilter/examples/append_header_ip/__main__.py index f715ce5..9c191ed 100644 --- a/src/purepythonmilter/examples/append_header_ip/__main__.py +++ b/src/purepythonmilter/examples/append_header_ip/__main__.py @@ -31,7 +31,7 @@ async def on_connect(cmd: Connect) -> Continue: at the later approriate end_of_message stage for you. """ global _headername, logger - match cmd.connection_info_args: + match cmd.connection_info_args: # noqa: E999 case ConnectionInfoArgsIPv4() | ConnectionInfoArgsIPv6(): ip = str(cmd.connection_info_args.addr) logger.info(f"on_connect(): adding header '{_headername}: {ip}'") diff --git a/src/purepythonmilter/protocol/commands.py b/src/purepythonmilter/protocol/commands.py index 6a2e626..dfa74a2 100644 --- a/src/purepythonmilter/protocol/commands.py +++ b/src/purepythonmilter/protocol/commands.py @@ -152,7 +152,7 @@ def _decode_connection_info(self) -> models.ConnectionInfoArgs: f"Could not decode hostname in socket data {hostname_bin=!r}" ) from e - match self._decode_socket_data(socket_data.rstrip(b"\x00")): + match self._decode_socket_data(socket_data.rstrip(b"\x00")): # noqa: E999 case ipaddress.IPv4Address() as ip, int() as port: return models.ConnectionInfoArgsIPv4( hostname=hostname, addr=ip, port=port diff --git a/src/purepythonmilter/server/session.py b/src/purepythonmilter/server/session.py index 0e9d182..eb12cbe 100644 --- a/src/purepythonmilter/server/session.py +++ b/src/purepythonmilter/server/session.py @@ -153,7 +153,7 @@ async def _commands_consumer(self) -> None: await self._process_queue_item(queue_item) async def _process_queue_item(self, queue_item: QueueEntry) -> None: - match queue_item.command: + match queue_item.command: # noqa: E999 case commands.OptionsNegotiate(): # This one is an exception to the rule; implemented here. await self.on_options_negotiate(queue_item.command) diff --git a/tests/protocol/test_commands.py b/tests/protocol/test_commands.py index 7f5589b..ab9cc61 100644 --- a/tests/protocol/test_commands.py +++ b/tests/protocol/test_commands.py @@ -48,7 +48,7 @@ def _make_options_negotiate_data( ) action_int = int.from_bytes(optneg_data_no_flags[4:8], "big", signed=False) proto_int = int.from_bytes(optneg_data_no_flags[8:12], "big", signed=False) - match flag: + match flag: # noqa: E999 case ( definitions.ProtocolFlagsDisableCallback() | definitions.ProtocolFlagsOther()