From 05a274a5f33d95a0a1611cc226b824a39e6843bf Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 21 Feb 2023 11:17:10 +0000 Subject: [PATCH] Enable more ruff checks in deltachat-rpc-client --- deltachat-rpc-client/pyproject.toml | 30 ++++++++++++++++++- .../src/deltachat_rpc_client/account.py | 4 +-- .../src/deltachat_rpc_client/chat.py | 7 +++-- .../src/deltachat_rpc_client/client.py | 6 ++-- .../src/deltachat_rpc_client/contact.py | 4 +-- .../src/deltachat_rpc_client/deltachat.py | 6 ++-- .../src/deltachat_rpc_client/events.py | 6 ++-- .../src/deltachat_rpc_client/message.py | 4 +-- .../src/deltachat_rpc_client/pytestplugin.py | 2 +- deltachat-rpc-client/tests/test_something.py | 3 +- deltachat-rpc-client/tests/test_webxdc.py | 1 - 11 files changed, 53 insertions(+), 20 deletions(-) diff --git a/deltachat-rpc-client/pyproject.toml b/deltachat-rpc-client/pyproject.toml index ef76fa82b..f7d7fc905 100644 --- a/deltachat-rpc-client/pyproject.toml +++ b/deltachat-rpc-client/pyproject.toml @@ -25,7 +25,35 @@ deltachat_rpc_client = [ line-length = 120 [tool.ruff] -select = ["E", "F", "W", "N", "YTT", "B", "C4", "ISC", "ICN", "PT", "RET", "SIM", "TID", "ARG", "DTZ", "ERA", "PLC", "PLE", "PLW", "PIE", "COM"] +select = [ + "E", "W", # pycodestyle + "F", # Pyflakes + "N", # pep8-naming + "I", # isort + + "ARG", # flake8-unused-arguments + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "COM", # flake8-commas + "DTZ", # flake8-datetimez + "ICN", # flake8-import-conventions + "ISC", # flake8-implicit-str-concat + "PIE", # flake8-pie + "PT", # flake8-pytest-style + "RET", # flake8-return + "SIM", # flake8-simplify + "TCH", # flake8-type-checking + "TID", # flake8-tidy-imports + "YTT", # flake8-2020 + + "ERA", # eradicate + + "PLC", # Pylint Convention + "PLE", # Pylint Error + "PLW", # Pylint Warning + + "RUF006" # asyncio-dangling-task +] line-length = 120 [tool.isort] diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/account.py b/deltachat-rpc-client/src/deltachat_rpc_client/account.py index 63a9b169c..86ee9addb 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/account.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/account.py @@ -1,15 +1,15 @@ -from typing import TYPE_CHECKING, List, Optional, Tuple, Union from dataclasses import dataclass +from typing import TYPE_CHECKING, List, Optional, Tuple, Union from ._utils import AttrDict from .chat import Chat from .const import ChatlistFlag, ContactFlag, SpecialContactId from .contact import Contact from .message import Message -from .rpc import Rpc if TYPE_CHECKING: from .deltachat import DeltaChat + from .rpc import Rpc @dataclass diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py index c2e5ca364..443927b38 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py @@ -1,16 +1,17 @@ import calendar -from datetime import datetime -from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union from dataclasses import dataclass +from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union from ._utils import AttrDict from .const import ChatVisibility from .contact import Contact from .message import Message -from .rpc import Rpc if TYPE_CHECKING: + from datetime import datetime + from .account import Account + from .rpc import Rpc @dataclass diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/client.py b/deltachat-rpc-client/src/deltachat_rpc_client/client.py index 393ac3cc7..1f1a14506 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/client.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/client.py @@ -2,6 +2,7 @@ import inspect import logging from typing import ( + TYPE_CHECKING, Callable, Coroutine, Dict, @@ -13,8 +14,6 @@ from typing import ( Union, ) -from deltachat_rpc_client.account import Account - from ._utils import ( AttrDict, parse_system_add_remove, @@ -31,6 +30,9 @@ from .events import ( RawEvent, ) +if TYPE_CHECKING: + from deltachat_rpc_client.account import Account + class Client: """Simple Delta Chat client that listen to events of a single account.""" diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/contact.py b/deltachat-rpc-client/src/deltachat_rpc_client/contact.py index 7999d59ed..9e9417790 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/contact.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/contact.py @@ -1,12 +1,12 @@ -from typing import TYPE_CHECKING from dataclasses import dataclass +from typing import TYPE_CHECKING from ._utils import AttrDict -from .rpc import Rpc if TYPE_CHECKING: from .account import Account from .chat import Chat + from .rpc import Rpc @dataclass diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py b/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py index 16afe458b..aea4ccd1f 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py @@ -1,8 +1,10 @@ -from typing import Dict, List +from typing import TYPE_CHECKING, Dict, List from ._utils import AttrDict from .account import Account -from .rpc import Rpc + +if TYPE_CHECKING: + from .rpc import Rpc class DeltaChat: diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/events.py b/deltachat-rpc-client/src/deltachat_rpc_client/events.py index 0e160445c..0330c87d9 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/events.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/events.py @@ -2,11 +2,13 @@ import inspect import re from abc import ABC, abstractmethod -from typing import Callable, Iterable, Iterator, Optional, Set, Tuple, Union +from typing import TYPE_CHECKING, Callable, Iterable, Iterator, Optional, Set, Tuple, Union -from ._utils import AttrDict from .const import EventType +if TYPE_CHECKING: + from ._utils import AttrDict + def _tuple_of(obj, type_: type) -> tuple: if not obj: diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/message.py b/deltachat-rpc-client/src/deltachat_rpc_client/message.py index 7784d8dac..224931ba1 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/message.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/message.py @@ -1,13 +1,13 @@ import json -from typing import TYPE_CHECKING, Union from dataclasses import dataclass +from typing import TYPE_CHECKING, Union from ._utils import AttrDict from .contact import Contact -from .rpc import Rpc if TYPE_CHECKING: from .account import Account + from .rpc import Rpc @dataclass diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py index 87e97f0e0..065f7744e 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py @@ -1,8 +1,8 @@ +import asyncio import json import os from typing import AsyncGenerator, List, Optional -import asyncio import aiohttp import pytest_asyncio diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 47b4cf8e3..fc05854d6 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -1,8 +1,7 @@ +import asyncio from unittest.mock import MagicMock import pytest -import asyncio - from deltachat_rpc_client import EventType, events from deltachat_rpc_client.rpc import JsonRpcError diff --git a/deltachat-rpc-client/tests/test_webxdc.py b/deltachat-rpc-client/tests/test_webxdc.py index 22d9db0b4..8a0584d03 100644 --- a/deltachat-rpc-client/tests/test_webxdc.py +++ b/deltachat-rpc-client/tests/test_webxdc.py @@ -1,5 +1,4 @@ import pytest - from deltachat_rpc_client import EventType