Skip to content

Commit

Permalink
Suppress Ruff's (unsupported) Structural Pattern Matching syntax errors
Browse files Browse the repository at this point in the history
Work-around with suppression of syntax error printed has been added in
version 0.0.245.

- astral-sh/ruff#2697
- astral-sh/ruff#2505 (comment)
  • Loading branch information
gertvdijk committed Feb 11, 2023
1 parent c578171 commit 51d5b1b
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ development = [
"pytest",
"pyupgrade",
"reuse",
"ruff",
"ruff>=0.0.245",
"setuptools-scm[toml]>=6.2",
"twine",
"validate-pyproject[all]",
Expand Down
4 changes: 1 addition & 3 deletions run-all-linters
Original file line number Diff line number Diff line change
Expand Up @@ -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. 😥
Expand Down
2 changes: 1 addition & 1 deletion src/purepythonmilter/api/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _:
Expand Down
2 changes: 1 addition & 1 deletion src/purepythonmilter/examples/append_header_ip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")
Expand Down
2 changes: 1 addition & 1 deletion src/purepythonmilter/protocol/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/purepythonmilter/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/protocol/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 51d5b1b

Please sign in to comment.