Skip to content

Commit

Permalink
chore: update ruff, update minimum version for ruff to Python 3.9 and…
Browse files Browse the repository at this point in the history
… fix linting errors
  • Loading branch information
DonDebonair committed Nov 22, 2024
1 parent 920ac00 commit e16afcb
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: chartboost/ruff-action@v1
- uses: chartboost/ruff-action@v1
- uses: astral-sh/ruff-action@v1
- uses: astral-sh/ruff-action@v1
with:
args: "format --check"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.4
rev: v0.8.0
hooks:
# Run the linter.
- id: ruff
Expand Down
5 changes: 3 additions & 2 deletions machine/clients/slack.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import asyncio
from collections.abc import AsyncGenerator, Awaitable
from datetime import datetime
from typing import Any, AsyncGenerator, Awaitable, Callable
from typing import Any, Callable
from zoneinfo import ZoneInfo

from slack_sdk.errors import SlackApiError
from slack_sdk.models.views import View
Expand All @@ -13,7 +15,6 @@
from slack_sdk.web.async_client import AsyncWebClient
from slack_sdk.web.async_slack_response import AsyncSlackResponse
from structlog.stdlib import get_logger
from zoneinfo import ZoneInfo

from machine.models import Channel, User
from machine.utils.datetime import calculate_epoch
Expand Down
5 changes: 3 additions & 2 deletions machine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import inspect
import os
import sys
from collections.abc import Awaitable
from inspect import Signature
from typing import Awaitable, Callable, Literal, cast
from typing import Callable, Literal, cast
from zoneinfo import ZoneInfo

import dill
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from slack_sdk.socket_mode.aiohttp import SocketModeClient
from slack_sdk.web.async_client import AsyncWebClient
from structlog.stdlib import get_logger
from zoneinfo import ZoneInfo

from machine.clients.slack import SlackClient
from machine.handlers import (
Expand Down
3 changes: 2 additions & 1 deletion machine/handlers/command_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import contextlib
from typing import Any, AsyncGenerator, Awaitable, Callable, Union, cast
from collections.abc import AsyncGenerator, Awaitable
from typing import Any, Callable, Union, cast

from slack_sdk.models import JsonObject
from slack_sdk.socket_mode.async_client import AsyncBaseSocketModeClient
Expand Down
3 changes: 2 additions & 1 deletion machine/handlers/event_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import asyncio
from typing import Any, Awaitable, Callable
from collections.abc import Awaitable
from typing import Any, Callable

from slack_sdk.socket_mode.async_client import AsyncBaseSocketModeClient
from slack_sdk.socket_mode.request import SocketModeRequest
Expand Down
3 changes: 2 additions & 1 deletion machine/handlers/interactive_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import asyncio
import contextlib
import re
from typing import AsyncGenerator, Awaitable, Callable, Union, cast
from collections.abc import AsyncGenerator, Awaitable
from typing import Callable, Union, cast

from slack_sdk.models.views import View
from slack_sdk.socket_mode.async_client import AsyncBaseSocketModeClient
Expand Down
3 changes: 2 additions & 1 deletion machine/handlers/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import asyncio
import re
from typing import Any, Awaitable, Callable, Mapping
from collections.abc import Awaitable, Mapping
from typing import Any, Callable

from slack_sdk.socket_mode.async_client import AsyncBaseSocketModeClient
from slack_sdk.socket_mode.request import SocketModeRequest
Expand Down
4 changes: 2 additions & 2 deletions machine/models/channel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import Optional

from pydantic import BaseModel, ConfigDict

Expand Down Expand Up @@ -36,7 +36,7 @@ class Channel(BaseModel):
user: Optional[str] = None
topic: Optional[PurposeTopic] = None
purpose: Optional[PurposeTopic] = None
previous_names: Optional[List[str]] = None
previous_names: Optional[list[str]] = None

@property
def identifier(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion machine/models/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import re
from collections.abc import AsyncGenerator, Awaitable
from dataclasses import dataclass, field
from inspect import Signature
from typing import Any, AsyncGenerator, Awaitable, Callable, Union
from typing import Any, Callable, Union

from slack_sdk.models import JsonObject

Expand Down
37 changes: 18 additions & 19 deletions machine/models/interactive.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import annotations

from datetime import date, time
from typing import Any, Dict, List, Literal, Optional, Union
from typing import Annotated, Any, Literal, Optional, Union

from pydantic import BaseModel, Field, TypeAdapter
from pydantic.functional_validators import PlainValidator, model_validator
from pydantic_core.core_schema import ValidationInfo
from slack_sdk.models.blocks import Block as SlackSDKBlock
from typing_extensions import Annotated


class TypedModel(BaseModel):
Expand Down Expand Up @@ -77,7 +76,7 @@ class Option(BaseModel):

class CheckboxValues(TypedModel):
type: Literal["checkboxes"]
selected_options: List[Option]
selected_options: list[Option]


class DatepickerValue(TypedModel):
Expand Down Expand Up @@ -117,27 +116,27 @@ class ExternalSelectValue(TypedModel):

class MultiStaticSelectValues(TypedModel):
type: Literal["multi_static_select"]
selected_options: List[Option]
selected_options: list[Option]


class MultiChannelSelectValues(TypedModel):
type: Literal["multi_channels_select"]
selected_channels: List[str]
selected_channels: list[str]


class MultiConversationSelectValues(TypedModel):
type: Literal["multi_conversations_select"]
selected_conversations: List[str]
selected_conversations: list[str]


class MultiUserSelectValues(TypedModel):
type: Literal["multi_users_select"]
selected_users: List[str]
selected_users: list[str]


class MultiExternalSelectValues(TypedModel):
type: Literal["multi_external_select"]
selected_options: List[str]
selected_options: list[str]


class NumberValue(TypedModel):
Expand Down Expand Up @@ -197,7 +196,7 @@ class UrlValue(TypedModel):


class State(BaseModel):
values: Dict[str, Dict[str, Values]]
values: dict[str, dict[str, Values]]


class BaseAction(TypedModel):
Expand All @@ -221,7 +220,7 @@ class ButtonAction(BaseAction):

class CheckboxAction(BaseAction):
type: Literal["checkboxes"]
selected_options: List[Option]
selected_options: list[Option]


class DatepickerAction(BaseAction):
Expand Down Expand Up @@ -256,27 +255,27 @@ class ExternalSelectAction(BaseAction):

class MultiStaticSelectAction(BaseAction):
type: Literal["multi_static_select"]
selected_options: List[Option]
selected_options: list[Option]


class MultiChannelSelectAction(BaseAction):
type: Literal["multi_channels_select"]
selected_channels: List[str]
selected_channels: list[str]


class MultiConversationSelectAction(BaseAction):
type: Literal["multi_conversations_select"]
selected_conversations: List[str]
selected_conversations: list[str]


class MultiUserSelectAction(BaseAction):
type: Literal["multi_users_select"]
selected_users: List[str]
selected_users: list[str]


class MultiExternalSelectAction(BaseAction):
type: Literal["multi_external_select"]
selected_options: List[str]
selected_options: list[str]


class TimepickerAction(BaseAction):
Expand Down Expand Up @@ -348,14 +347,14 @@ class Message(BaseModel):
app_id: str
text: str
team: str
blocks: List[Block]
blocks: list[Block]


class View(BaseModel):
id: str
team_id: str
type: Literal["modal", "home"]
blocks: List[Block]
blocks: list[Block]
private_metadata: str
callback_id: str
state: State
Expand Down Expand Up @@ -395,7 +394,7 @@ class BlockActionsPayload(TypedModel):
view: Optional[View] = None
state: Optional[State] = None
response_url: Optional[str] = None
actions: List[Action]
actions: list[Action]

@model_validator(mode="after")
def validate_view_or_message(self) -> BlockActionsPayload:
Expand All @@ -420,7 +419,7 @@ class ViewSubmissionPayload(TypedModel):
api_app_id: str
token: str
trigger_id: str
response_urls: List[ResponseUrlForView]
response_urls: list[ResponseUrlForView]
is_enterprise_install: bool


Expand Down
3 changes: 2 additions & 1 deletion machine/plugins/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Sequence
from datetime import datetime
from typing import Any, Sequence
from typing import Any

from slack_sdk.models.attachments import Attachment
from slack_sdk.models.blocks import Block
Expand Down
3 changes: 2 additions & 1 deletion machine/plugins/block_action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from slack_sdk.models.attachments import Attachment
from slack_sdk.models.blocks import Block
Expand Down
3 changes: 2 additions & 1 deletion machine/plugins/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Sequence
from collections.abc import Sequence
from typing import Any

from slack_sdk.models.attachments import Attachment
from slack_sdk.models.blocks import Block
Expand Down
3 changes: 2 additions & 1 deletion machine/plugins/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import inspect
import re
from collections.abc import Awaitable
from datetime import datetime, tzinfo
from typing import Any, Awaitable, Callable, Protocol, TypeVar, Union, cast
from typing import Any, Callable, Protocol, TypeVar, Union, cast

from structlog.stdlib import get_logger
from typing_extensions import ParamSpec
Expand Down
3 changes: 2 additions & 1 deletion machine/plugins/message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Sequence
from datetime import datetime
from typing import Any, Sequence, cast
from typing import Any, cast

from slack_sdk.models.attachments import Attachment
from slack_sdk.models.blocks import Block
Expand Down
3 changes: 2 additions & 1 deletion machine/plugins/modals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Sequence
from collections.abc import Sequence
from typing import Any

from slack_sdk.models.attachments import Attachment
from slack_sdk.models.blocks import Block
Expand Down
3 changes: 1 addition & 2 deletions machine/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from importlib import import_module
from typing import Tuple

from structlog.stdlib import get_logger

Expand All @@ -9,7 +8,7 @@
logger = get_logger(__name__)


def import_settings(settings_module: str = "local_settings") -> Tuple[CaseInsensitiveDict, bool]:
def import_settings(settings_module: str = "local_settings") -> tuple[CaseInsensitiveDict, bool]:
default_settings = {
"PLUGINS": [
"machine.plugins.builtin.general.PingPongPlugin",
Expand Down
3 changes: 2 additions & 1 deletion machine/storage/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any, Mapping
from collections.abc import Mapping
from typing import Any


class MachineBaseStorage(ABC):
Expand Down
3 changes: 2 additions & 1 deletion machine/storage/backends/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import calendar
import datetime
import typing
from collections.abc import Mapping
from contextlib import AsyncExitStack
from typing import Any, Mapping, cast
from typing import Any, cast

import aioboto3
from botocore.exceptions import ClientError
Expand Down
3 changes: 2 additions & 1 deletion machine/storage/backends/memory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import sys
from collections.abc import Mapping
from datetime import datetime, timedelta
from typing import Any, Mapping
from typing import Any

from machine.storage.backends.base import MachineBaseStorage

Expand Down
3 changes: 2 additions & 1 deletion machine/storage/backends/redis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Mapping
from collections.abc import Mapping
from typing import Any

from redis.asyncio import Redis

Expand Down
3 changes: 2 additions & 1 deletion machine/storage/backends/sqlite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import time
from typing import Any, Mapping
from collections.abc import Mapping
from typing import Any

import aiosqlite

Expand Down
Loading

0 comments on commit e16afcb

Please sign in to comment.