From d6c580397c05e7138fb2dba7a0be1d3927c9c89c Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 13 Dec 2023 05:51:16 -0600 Subject: [PATCH] Update ruff config --- .pre-commit-config.yaml | 4 ++-- comm/__init__.py | 2 +- comm/base_comm.py | 26 ++++++++++++++------------ pyproject.toml | 38 ++++++++++++++++++++++++++++++++------ 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 509fc97..d05aaa2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.27.2 + rev: 0.27.3 hooks: - id: check-github-workflows @@ -66,7 +66,7 @@ repos: additional_dependencies: ["traitlets>=5.13"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.6 + rev: v0.1.7 hooks: - id: ruff types_or: [python, jupyter] diff --git a/comm/__init__.py b/comm/__init__.py index b315ecf..bb1b00e 100644 --- a/comm/__init__.py +++ b/comm/__init__.py @@ -48,7 +48,7 @@ def _get_comm_manager() -> CommManager: This method is intended to be replaced if needed (if you want to manage multiple CommManagers). """ - global _comm_manager + global _comm_manager # noqa: PLW0603 if _comm_manager is None: _comm_manager = CommManager() diff --git a/comm/base_comm.py b/comm/base_comm.py index 058e557..f94127f 100644 --- a/comm/base_comm.py +++ b/comm/base_comm.py @@ -70,13 +70,14 @@ def __init__( def publish_msg( self, - msg_type: str, - data: MaybeDict = None, - metadata: MaybeDict = None, - buffers: BuffersType = None, - **keys: t.Any, + msg_type: str, # noqa: ARG002 + data: MaybeDict = None, # noqa: ARG002 + metadata: MaybeDict = None, # noqa: ARG002 + buffers: BuffersType = None, # noqa: ARG002 + **keys: t.Any, # noqa: ARG002 ) -> None: - raise NotImplementedError("publish_msg Comm method is not implemented") + msg = "publish_msg Comm method is not implemented" + raise NotImplementedError(msg) def __del__(self) -> None: """trigger close on gc""" @@ -84,7 +85,7 @@ def __del__(self) -> None: # publishing messages - def open( # noqa: A003 + def open( self, data: MaybeDict = None, metadata: MaybeDict = None, buffers: BuffersType = None ) -> None: """Open the frontend-side version of this comm""" @@ -93,7 +94,8 @@ def open( # noqa: A003 data = self._open_data comm_manager = comm.get_comm_manager() if comm_manager is None: - raise RuntimeError("Comms cannot be opened without a comm_manager.") + msg = "Comms cannot be opened without a comm_manager." # type:ignore[unreachable] + raise RuntimeError(msg) comm_manager.register_comm(self) try: @@ -211,7 +213,7 @@ def register_target(self, target_name: str, f: CommTargetCallback | str) -> None self.targets[target_name] = t.cast(CommTargetCallback, f) - def unregister_target(self, target_name: str, f: CommTargetCallback) -> CommTargetCallback: + def unregister_target(self, target_name: str, f: CommTargetCallback) -> CommTargetCallback: # noqa: ARG002 """Unregister a callable registered with register_target""" return self.targets.pop(target_name) @@ -245,7 +247,7 @@ def get_comm(self, comm_id: str) -> BaseComm | None: # Message handlers - def comm_open(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: + def comm_open(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: # noqa: ARG002 """Handler for comm_open messages""" from comm import create_comm @@ -278,7 +280,7 @@ def comm_open(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: exc_info=True, ) - def comm_msg(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: + def comm_msg(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: # noqa: ARG002 """Handler for comm_msg messages""" content = msg["content"] comm_id = content["comm_id"] @@ -291,7 +293,7 @@ def comm_msg(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: except Exception: logger.error("Exception in comm_msg for %s", comm_id, exc_info=True) - def comm_close(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: + def comm_close(self, stream: ZMQStream, ident: str, msg: MessageType) -> None: # noqa: ARG002 """Handler for comm_close messages""" content = msg["content"] comm_id = content["comm_id"] diff --git a/pyproject.toml b/pyproject.toml index 8fdacdf..a7d441d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,11 +86,33 @@ warn_unreachable = true line-length = 100 [tool.ruff.lint] -select = [ - "A", "B", "C", "E", "F", "I", "N", "Q", "RUF", "S", "T", - "UP", "W", "YTT", +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PTH", # flake8-use-pathlib + "PT", # flake8-pytest-style + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "PYI", # flake8-pyi + "S", # flake8-bandit ] ignore = [ + "PLR", # Design related pylint codes + "S101", # Use of `assert` detected + "G201" # Logging `.exception(...)` should be used instead ] unfixable = [ # Don't touch print statements @@ -100,8 +122,12 @@ unfixable = [ ] [tool.ruff.lint.per-file-ignores] -# S101 Use of `assert` detected -"tests/*" = ["S101"] +"tests/*" = [] + +[tool.ruff.lint.flake8-pytest-style] +fixture-parentheses = false +mark-parentheses = false +parametrize-names-type = "csv" [tool.repo-review] -ignore = ["PY007", "PP308", "PY004", "GH102", "MY101", "RTD100"] +ignore = ["PP308", "PY004", "GH102", "MY101", "RTD100"]