Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
chore: Use ruff and fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Jan 16, 2024
1 parent 28c639f commit 24e1362
Show file tree
Hide file tree
Showing 43 changed files with 154 additions and 343 deletions.
21 changes: 0 additions & 21 deletions .vim/settings.json

This file was deleted.

19 changes: 4 additions & 15 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,12 @@ test:
poetry run pytest

lint:
poetry run black --check pollbot
poetry run isort \
--skip __init__.py \
--check-only pollbot
poetry run flake8 pollbot
poetry run ruff check ./pollbot --show-source
poetry run ruff format ./pollbot --diff

format:
# remove unused imports
poetry run autoflake \
--remove-all-unused-imports \
--recursive \
--exclude=__init__.py,.venv \
--in-place pollbot
poetry run black pollbot
poetry run isort pollbot \
--skip __init__.py

poetry run ruff check --fix ./pollbot
poetry run ruff format ./pollbot

# Watch for something
# E.g. `just watch lint` or `just watch test`
Expand Down
189 changes: 27 additions & 162 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions pollbot/display/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Display helper for misc stuff."""
from typing import Tuple, Union

from sqlalchemy.orm.scoping import scoped_session
from telegram.inline.inlinekeyboardmarkup import InlineKeyboardMarkup

Expand All @@ -13,7 +11,7 @@

def get_help_text_and_keyboard(
user: User, current_category: str
) -> Tuple[str, InlineKeyboardMarkup]:
) -> tuple[str, InlineKeyboardMarkup]:
"""Create the help message depending on the currently selected help category."""
categories = [
"creation",
Expand All @@ -32,7 +30,7 @@ def get_help_text_and_keyboard(

def get_poll_list(
session: scoped_session, user: User, offset: int, closed: bool = False
) -> Union[Tuple[str, InlineKeyboardMarkup], Tuple[str, None]]:
) -> tuple[str, InlineKeyboardMarkup] | tuple[str, None]:
"""Get the a list of polls for the user."""
polls = (
session.query(Poll)
Expand Down
10 changes: 4 additions & 6 deletions pollbot/display/poll/compilation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List, Optional, Tuple

from sqlalchemy.orm.scoping import scoped_session
from telegram.inline.inlinekeyboardmarkup import InlineKeyboardMarkup

Expand All @@ -16,9 +14,9 @@
def get_poll_text_and_vote_keyboard(
session: scoped_session,
poll: Poll,
user: Optional[User] = None,
user: User | None = None,
show_back: bool = False,
) -> Tuple[str, InlineKeyboardMarkup]:
) -> tuple[str, InlineKeyboardMarkup]:
"""Get the text and the vote keyboard."""
text, summarize = get_poll_text_and_summarize(
session,
Expand All @@ -38,7 +36,7 @@ def get_poll_text(session: scoped_session, poll: Poll) -> str:

def get_poll_text_and_summarize(
session: scoped_session, poll: Poll
) -> Tuple[str, bool]:
) -> tuple[str, bool]:
"""Get the poll text and vote keyboard."""
summarize = poll.permanently_summarized or poll.summarize

Expand Down Expand Up @@ -70,7 +68,7 @@ def get_poll_text_and_summarize(

def compile_poll_text(
session: scoped_session, poll: Poll, summarize: bool = False
) -> List[str]:
) -> list[str]:
"""Create the text of the poll."""
context = Context(session, poll)

Expand Down
3 changes: 1 addition & 2 deletions pollbot/display/poll/indices.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import string
from typing import List, Union

from sqlalchemy.orm.collections import InstrumentedList

from pollbot.models.option import Option


def get_option_indices(options: Union[List[Option], InstrumentedList]) -> List[str]:
def get_option_indices(options: list[Option] | InstrumentedList) -> list[str]:
"""Simple helper to dynamically create indices/letters for option displaying."""
indices = list(string.ascii_lowercase)
if len(options) > len(indices):
Expand Down
6 changes: 3 additions & 3 deletions pollbot/display/poll/option.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Poll text compilation for options."""
import math
from typing import Any, List, Union
from typing import Any

from sqlalchemy.orm.scoping import scoped_session
from telegram.chat import Chat
Expand All @@ -18,7 +18,7 @@
from .vote import get_doodle_vote_lines, get_vote_lines


def next_option(tg_chat: Chat, poll: Poll, added_options: List[str]) -> None:
def next_option(tg_chat: Chat, poll: Poll, added_options: list[str]) -> None:
"""Send the options message during the creation.
This function also has a failsafe in it, that rollbacks the entire transaction,
Expand Down Expand Up @@ -47,7 +47,7 @@ def next_option(tg_chat: Chat, poll: Poll, added_options: List[str]) -> None:

def get_option_information(
session: scoped_session, poll: Poll, context: Context, summarize: bool
) -> List[Union[Any, str]]:
) -> list[Any | str]:
"""Compile all information about a poll option."""
lines = []
# Sort the options accordingly to the polls settings
Expand Down
Loading

0 comments on commit 24e1362

Please sign in to comment.