From 7238df8536e109c11d6e2702c1c3f8c359fcd7e8 Mon Sep 17 00:00:00 2001 From: Niels Buwen Date: Mon, 19 Feb 2024 13:53:48 +0100 Subject: [PATCH] Lint with new version --- pyproject.toml | 6 ++++-- skillbridge/__init__.py | 32 ++++++++++++++--------------- skillbridge/__main__.py | 2 +- skillbridge/client/channel.py | 6 ++++-- skillbridge/client/globals.py | 2 +- skillbridge/client/hints.py | 12 +++++------ skillbridge/client/workspace.py | 2 +- skillbridge/server/python_server.py | 8 +++++--- tests/test_channel.py | 4 ++-- tests/test_workspace.py | 2 +- 10 files changed, 41 insertions(+), 35 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index dc3c81b..ca32d6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,6 +113,7 @@ ignore = [ "ANN10", "ANN401", "B028", "COM812", + "CPY001", "D", "EM101", "EM102", "FBT001", "FBT002", @@ -120,11 +121,12 @@ ignore = [ "ISC001", "N999", "PD901", - "PLR0911", + "PLR0911", "PLR6301", + "PLW1641", "PLW3201", "PT001", "PT013", "PTH123", "Q000", - "S101", "S108", "S310", "S311", + "S101", "S108", "S310", "S311", "S404", "T201", "TCH001", "TCH002", "TCH003", "TID252", diff --git a/skillbridge/__init__.py b/skillbridge/__init__.py index 5e95a92..5c91a5a 100644 --- a/skillbridge/__init__.py +++ b/skillbridge/__init__.py @@ -14,27 +14,27 @@ from .client.workspace import Workspace, current_workspace __all__ = [ - 'Workspace', - 'Var', + 'Function', + 'GlobalVar', + 'Globals', + 'Key', + 'LazyList', 'ParseError', + 'RemoteObject', + 'RemoteTable', + 'RemoteVector', + 'SkillCode', + 'SkillList', + 'SkillTuple', 'Symbol', - 'Key', - 'generate_static_completion', + 'Var', + 'Workspace', 'current_workspace', + 'generate_static_completion', 'keys', - 'SkillTuple', - 'SkillList', - 'SkillCode', - 'Function', 'loop_var', 'loop_var_i', 'loop_var_j', - 'Globals', - 'GlobalVar', - 'RemoteTable', - 'RemoteVector', - 'RemoteObject', - 'LazyList', ] loop_var = Var('i') @@ -43,7 +43,7 @@ def generate_static_completion() -> None: - from mypy.stubgen import Options, generate_stubs + from mypy.stubgen import Options, generate_stubs # noqa: PLC0415 base = Path(__file__).parent.absolute() / 'client' annotation = base / 'workspace.pyi' @@ -83,7 +83,7 @@ def generate_static_completion() -> None: text = sub(r' {4}[a-z][a-zA-Z]+: FunctionCollection\n', '', text) annotation.write_text(text) - with open(annotation, 'a') as fout: + with open(annotation, 'a', encoding='utf-8') as fout: for key, value in ws.__dict__.items(): if not isinstance(value, FunctionCollection): continue diff --git a/skillbridge/__main__.py b/skillbridge/__main__.py index 16a351e..b88081b 100644 --- a/skillbridge/__main__.py +++ b/skillbridge/__main__.py @@ -30,7 +30,7 @@ def deprecated_command() -> None: # pragma: no cover def shell_command(ws_id: str | None, ping: bool) -> None: - import skillbridge + import skillbridge # noqa: PLC0415 variables = {name: getattr(skillbridge, name) for name in dir(skillbridge)} ws = skillbridge.Workspace.open(ws_id) diff --git a/skillbridge/client/channel.py b/skillbridge/client/channel.py index 574ae08..5400647 100644 --- a/skillbridge/client/channel.py +++ b/skillbridge/client/channel.py @@ -187,7 +187,9 @@ def create_channel_class() -> type[TcpChannel]: class WindowsChannel(TcpChannel): def configure(self, sock: socket) -> None: try: - from socket import SIO_LOOPBACK_FAST_PATH # type: ignore[attr-defined] + from socket import ( # type: ignore[attr-defined] # noqa: PLC0415 + SIO_LOOPBACK_FAST_PATH, + ) sock.ioctl( # type: ignore[attr-defined] SIO_LOOPBACK_FAST_PATH, @@ -206,7 +208,7 @@ def create_address(id_: Any) -> Any: else: def create_channel_class() -> type[TcpChannel]: - from socket import AF_UNIX + from socket import AF_UNIX # noqa: PLC0415 class UnixChannel(TcpChannel): address_family = AF_UNIX diff --git a/skillbridge/client/globals.py b/skillbridge/client/globals.py index f99b4ef..f478d4b 100644 --- a/skillbridge/client/globals.py +++ b/skillbridge/client/globals.py @@ -10,7 +10,7 @@ class GlobalVar: - __slots__ = 'name', '_channel', '_translator' + __slots__ = '_channel', '_translator', 'name' def __init__(self, name: str, channel: Channel, translator: Translator) -> None: self.name = name diff --git a/skillbridge/client/hints.py b/skillbridge/client/hints.py index 44f378b..323f78a 100644 --- a/skillbridge/client/hints.py +++ b/skillbridge/client/hints.py @@ -11,16 +11,16 @@ class Protocol: __all__ = [ - 'Number', - 'Symbol', + 'Function', 'Key', - 'SkillComponent', - 'SkillCode', + 'Number', 'Skill', - 'Function', - 'SkillTuple', + 'SkillCode', + 'SkillComponent', 'SkillList', + 'SkillTuple', 'SupportsReprSkill', + 'Symbol', ] Number = Union[int, float] diff --git a/skillbridge/client/workspace.py b/skillbridge/client/workspace.py index c874504..d2f0983 100644 --- a/skillbridge/client/workspace.py +++ b/skillbridge/client/workspace.py @@ -328,7 +328,7 @@ def register(self, function: Callable[..., Any]) -> Function: name = camel_to_snake(function.__name__) try: - prefix, rest = name.split('_', maxsplit=1) + prefix, _ = name.split('_', maxsplit=1) except ValueError: raise RuntimeError("Function does not have a prefix.") from None diff --git a/skillbridge/server/python_server.py b/skillbridge/server/python_server.py index bdeba4f..ff9489c 100644 --- a/skillbridge/server/python_server.py +++ b/skillbridge/server/python_server.py @@ -38,7 +38,7 @@ def read_from_skill(timeout: float | None) -> str: def create_windows_server_class(single: bool) -> type[BaseServer]: - from socketserver import TCPServer + from socketserver import TCPServer # noqa: PLC0415 class SingleWindowsServer(TCPServer): request_queue_size = 0 @@ -49,7 +49,9 @@ def __init__(self, port: int, handler: type[BaseRequestHandler]) -> None: def server_bind(self) -> None: try: - from socket import SIO_LOOPBACK_FAST_PATH # type: ignore[attr-defined] + from socket import ( # type: ignore[attr-defined] # noqa: PLC0415 + SIO_LOOPBACK_FAST_PATH, + ) self.socket.ioctl( # type: ignore[attr-defined] SIO_LOOPBACK_FAST_PATH, @@ -71,7 +73,7 @@ def data_windows_ready(timeout: float | None) -> bool: def create_unix_server_class(single: bool) -> type[BaseServer]: - from socketserver import UnixStreamServer + from socketserver import UnixStreamServer # noqa: PLC0415 class SingleUnixServer(UnixStreamServer): request_queue_size = 0 diff --git a/tests/test_channel.py b/tests/test_channel.py index 4b68bf6..d069c2a 100644 --- a/tests/test_channel.py +++ b/tests/test_channel.py @@ -48,7 +48,7 @@ def ws() -> Workspace: else: break else: - raise + raise RuntimeError yield ws ws.close() @@ -291,7 +291,7 @@ def test_warning_is_printed(server, ws): result = ws.ge.get_edit_cell_view() assert len(w) == 1 - assert w[0].category == UserWarning + assert w[0].category is UserWarning assert "This is a warning" in str(w[0].message) assert result == 1234 diff --git a/tests/test_workspace.py b/tests/test_workspace.py index 2fac7b7..b7911fd 100644 --- a/tests/test_workspace.py +++ b/tests/test_workspace.py @@ -3,7 +3,7 @@ from skillbridge import Workspace from skillbridge.client.channel import Channel from skillbridge.client.translator import DefaultTranslator -from skillbridge.client.workspace import _open_workspaces +from skillbridge.client.workspace import _open_workspaces # noqa: PLC2701 class DummyChannel(Channel):