Skip to content

Commit

Permalink
update ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bomzheg committed Sep 9, 2023
1 parent b08b43f commit 51df411
Show file tree
Hide file tree
Showing 113 changed files with 468 additions and 455 deletions.
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,31 @@ line_length = 99

[tool.ruff]
line-length = 99
select = ["ALL"]
ignore = [
"RUF001", "S101", "D", "ANN101", "S311", "PD008", "UP035", "C408", "C417",
"ANN102", "EM101", "TRY003", "PIE790", "RET505", "A003", "EM102", "RUF003",
"RET503", "RET502", "ARG005", "TCH003", "RUF002", "SIM108", "UP024",


# fixme
"ANN201", "SIM300", "COM812", "I001", "PLR0913", "UP015", "UP015", "B905",
"RUF007", "ANN401", "ANN001", "PLR0911", "FBT001", "ANN002", "ANN003",
"ARG002", "ARG001", "ANN204", "BLE001", "TRY400", "TCH001", "TCH002",
"PGH003", "FBT002", "N818", "PLW2901", "RET504", "PLC1901", "RUF006",
"FBT003", "SIM102", "S106", "PLR2004", "DTZ007", "ANN206", "PGH004",
"TRY301", "ANN202", "SIM114",
]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"tests/*" = [
"SLF001", "PLR2004", "PLR0913", "PT004", "PT023", "PT001",
"PLR0915", "ARG001", "PTH123" # fixme
]
"shvatka/api/*" = ["B008"]
"**/migrations/versions/*" = ["N999"]
"**/crawler/**parser/*" = ["PLR0912", "B904"]

[tool.flake8]
ignore = ['E203', 'E231', 'E241', 'W503']
Expand Down
2 changes: 1 addition & 1 deletion shvatka/api/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

import uvicorn as uvicorn
import uvicorn
from fastapi import FastAPI

from shvatka.api import dependencies, routes
Expand Down
2 changes: 1 addition & 1 deletion shvatka/api/dependencies/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_current_user() -> dto.User:


class AuthProvider:
def __init__(self, config: AuthConfig):
def __init__(self, config: AuthConfig) -> None:
self.config = config
self.pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
# to get a string like this run:
Expand Down
2 changes: 1 addition & 1 deletion shvatka/api/dependencies/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def dao_provider() -> HolderDao:


class DbProvider:
def __init__(self, pool: async_sessionmaker[AsyncSession], redis: Redis):
def __init__(self, pool: async_sessionmaker[AsyncSession], redis: Redis) -> None:
self.pool = pool
self.redis = redis
self.level_test = LevelTestingData()
Expand Down
2 changes: 1 addition & 1 deletion shvatka/api/dependencies/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from shvatka.core.services.game import get_active
from shvatka.infrastructure.db.dao.holder import HolderDao
from .db import dao_provider
from ...core.models import dto
from shvatka.core.models import dto


def active_game_provider() -> dto.Game:
Expand Down
2 changes: 1 addition & 1 deletion shvatka/api/dependencies/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ async def db_team_provider(
) -> dto.Team:
team = await get_my_team(player, dao.team_player)
if team is None:
raise exceptions.PlayerNotInTeam()
raise exceptions.PlayerNotInTeam(player=player)
return team
2 changes: 1 addition & 1 deletion shvatka/core/interfaces/scheduler/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .sheduler import Scheduler, LevelTestScheduler # noqa: F401
from .sheduler import Scheduler, LevelTestScheduler
34 changes: 17 additions & 17 deletions shvatka/core/models/dto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
from .achievement import Achievement # noqa: F401
from .chat import Chat # noqa: F401
from .common import DateRange # noqa: F401
from .forum_team import ForumTeam # noqa: F401
from .forum_user import ForumUser # noqa: F401
from .game import Game, FullGame, GameResults # noqa: F401
from .level import Level # noqa: F401
from .achievement import Achievement
from .chat import Chat
from .common import DateRange
from .forum_team import ForumTeam
from .forum_user import ForumUser
from .game import Game, FullGame, GameResults
from .level import Level
from .level_testing import (
LevelTestSuite,
LevelTestBucket,
LevelTestProtocol,
SimpleKey,
LevelTestingResult,
) # noqa: F401
from .levels_times import LevelTime, GameStat, LevelTimeOnGame # noqa: F401
from .organizer import Organizer, PrimaryOrganizer, SecondaryOrganizer # noqa: F401
from .player import Player, PlayerWithStat # noqa: F401
from .poll import VotedPlayer, Vote # noqa: F401
from .team import Team # noqa: F401
from .team_player import TeamPlayer, FullTeamPlayer, TeamDataRange # noqa: F401
)
from .levels_times import LevelTime, GameStat, LevelTimeOnGame
from .organizer import Organizer, PrimaryOrganizer, SecondaryOrganizer
from .player import Player, PlayerWithStat
from .poll import VotedPlayer, Vote
from .team import Team
from .team_player import TeamPlayer, FullTeamPlayer, TeamDataRange
from .time_key import (
KeyTime,
InsertedKey,
KeyInsertResult,
ParsedKey,
ParsedBonusKey,
) # noqa: F401
from .user import User, UserWithCreds # noqa: F401
from .waiver import Waiver, WaiverQuery # noqa: F401
)
from .user import User, UserWithCreds
from .waiver import Waiver, WaiverQuery
2 changes: 1 addition & 1 deletion shvatka/core/models/dto/achievement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime

from .player import Player
from .. import enums
from shvatka.core.models import enums


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion shvatka/core/models/dto/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_hint(self, level_number: int, hint_number: int) -> TimeHint:

@property
def hints_count(self) -> int:
return sum((level.hints_count for level in self.levels))
return sum(level.hints_count for level in self.levels)


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion shvatka/core/models/dto/levels_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __repr__(self) -> str:
class LevelTimeOnGame(LevelTime):
is_finished: bool

def __repr__(self):
def __repr__(self) -> str:
return super().__repr__()


Expand Down
2 changes: 1 addition & 1 deletion shvatka/core/models/dto/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .player import Player
from .team_player import TeamPlayer
from ..enums.played import Played
from shvatka.core.models.enums.played import Played


@dataclass
Expand Down
11 changes: 5 additions & 6 deletions shvatka/core/models/dto/scn/file_content.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Optional

from shvatka.core.models import dto
from shvatka.core.models.enums.hint_type import HintType
Expand Down Expand Up @@ -42,27 +41,27 @@ def public_filename(self):


@dataclass
class StoredFileMeta(FileMetaLightweight): # noqa FUCK YOU PYCHARM!
class StoredFileMeta(FileMetaLightweight):
file_content_link: FileContentLink


@dataclass
class UploadedFileMeta(FileMetaLightweight):
tg_link: Optional[TgLink] = None
tg_link: TgLink | None = None


@dataclass
class FileMeta(StoredFileMeta): # noqa
class FileMeta(StoredFileMeta):
tg_link: TgLink


@dataclass
class VerifiableFileMeta(FileMeta): # noqa
class VerifiableFileMeta(FileMeta):
author_id: int


@dataclass
class SavedFileMeta(VerifiableFileMeta): # noqa
class SavedFileMeta(VerifiableFileMeta):
id: int
author: dto.Player

Expand Down
4 changes: 2 additions & 2 deletions shvatka/core/models/dto/scn/hint_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def get_guids(self) -> list[str]:
class VenueHint(BaseHint, LocationMixin):
title: str
address: str
foursquare_id: typing.Optional[str] = None
foursquare_type: typing.Optional[str] = None
foursquare_id: str | None = None
foursquare_type: str | None = None
type: Literal["venue"] = HintType.venue.name

def get_guids(self) -> list[str]:
Expand Down
2 changes: 1 addition & 1 deletion shvatka/core/models/dto/scn/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def get_guids(self) -> list[str]:

@property
def hints_count(self) -> int:
return sum((time_hint.hints_count for time_hint in self.time_hints))
return sum(time_hint.hints_count for time_hint in self.time_hints)
30 changes: 15 additions & 15 deletions shvatka/core/models/dto/team_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .common import DateRange
from .player import Player
from .team import Team
from .. import enums
from shvatka.core.models import enums


@dataclass
Expand All @@ -26,21 +26,21 @@ class TeamPlayer:
_can_remove_players: bool

def __eq__(self, other) -> bool:
if not isinstance(other, (TeamPlayer, FullTeamPlayer)):
if not isinstance(other, TeamPlayer | FullTeamPlayer):
return NotImplemented
return self.id == other.id

def __hash__(self):
return hash(self.id)

def get_permissions(self) -> dict[str, bool]:
return dict(
can_manage_waivers=self._can_manage_waivers,
can_manage_players=self._can_remove_players,
can_change_team_name=self._can_change_team_name,
can_add_players=self._can_add_players,
can_remove_players=self._can_remove_players,
)
return {
"can_manage_waivers": self._can_manage_waivers,
"can_manage_players": self._can_remove_players,
"can_change_team_name": self._can_change_team_name,
"can_add_players": self._can_add_players,
"can_remove_players": self._can_remove_players,
}


@dataclass
Expand Down Expand Up @@ -94,17 +94,17 @@ def from_simple(cls, team_player: TeamPlayer, player: Player, team: Team):
date_left=team_player.date_left,
role=team_player.role,
emoji=team_player.emoji,
_can_manage_waivers=team_player._can_manage_waivers,
_can_manage_players=team_player._can_manage_players,
_can_change_team_name=team_player._can_change_team_name,
_can_add_players=team_player._can_add_players,
_can_remove_players=team_player._can_remove_players,
_can_manage_waivers=team_player._can_manage_waivers, # noqa: SLF001
_can_manage_players=team_player._can_manage_players, # noqa: SLF001
_can_change_team_name=team_player._can_change_team_name, # noqa: SLF001
_can_add_players=team_player._can_add_players, # noqa: SLF001
_can_remove_players=team_player._can_remove_players, # noqa: SLF001
team=team,
player=player,
)

def __eq__(self, other) -> bool:
if not isinstance(other, (TeamPlayer, FullTeamPlayer)):
if not isinstance(other, TeamPlayer | FullTeamPlayer):
return False
return self.id == other.id

Expand Down
11 changes: 5 additions & 6 deletions shvatka/core/services/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ async def complete_game(game: dto.Game, dao: GameCompleter):


async def check_no_other_game_active(dao: ActiveGameFinder, game: dto.Game):
if other_game := await dao.get_active_game():
if game.id != other_game.id:
raise AnotherGameIsActive(
game=game,
game_status=game.status,
)
if (other_game := await dao.get_active_game()) and game.id != other_game.id:
raise AnotherGameIsActive(
game=game,
game_status=game.status,
)


async def check_no_game_active(dao: ActiveGameFinder):
Expand Down
2 changes: 1 addition & 1 deletion shvatka/core/services/game_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async def finish_team(
locker: KeyCheckerFactory,
):
"""
два варианта:
Два варианта:
* уровень последний - поздравляем команду с завершением игры
* уровень последний и все команды финишировали - помечаем игру законченной,
пишем в лог игры уведомление о финале, уведомляем команды.
Expand Down
2 changes: 1 addition & 1 deletion shvatka/core/services/game_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ async def get_game_stat(game: dto.Game, player: dto.Player, dao: GameStatDao) ->
async def get_game_spy(game: dto.Game, player: dto.Player, dao: GameStatDao):
stat = await get_game_stat(game, player, dao)
result = []
for team, lts in stat.level_times.items():
for lts in stat.level_times.values():
result.append(lts[-1])
return result
2 changes: 1 addition & 1 deletion shvatka/core/services/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def get_bonus_value(self, key: str, level: dto.Level) -> float:
for bonus_key in level.get_bonus_keys():
if bonus_key.text == key:
return bonus_key.bonus_minutes
assert False
raise AssertionError

async def parse_key(self, key: str, level: dto.Level) -> dto.ParsedKey:
if key in level.get_bonus_keys_texts():
Expand Down
10 changes: 5 additions & 5 deletions shvatka/core/services/organizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def check_game_token(game: dto.Game, manage_token: str):

async def save_invite_to_orgs(game: dto.Game, inviter: dto.Player, dao: InviteSaver) -> str:
return await dao.save_new_invite(
dct=dict(
game_id=game.id,
inviter_id=inviter.id,
type_=InviteType.add_org.name,
)
dct={
"game_id": game.id,
"inviter_id": inviter.id,
"type_": InviteType.add_org.name,
}
)


Expand Down
14 changes: 7 additions & 7 deletions shvatka/core/services/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def get_team_players(team: dto.Team, dao: TeamPlayersGetter) -> Sequence[d

async def save_promotion_invite(inviter: dto.Player, dao: InviteSaver) -> str:
return await dao.save_new_invite(
dct=dict(inviter_id=inviter.id, type_=InviteType.promote_author.name)
dct={"inviter_id": inviter.id, "type_": InviteType.promote_author.name}
)


Expand All @@ -246,7 +246,7 @@ async def check_promotion_invite(inviter: dto.Player, token: str, dao: InviterDa

async def save_promotion_confirm_invite(inviter: dto.Player, dao: InviteSaver) -> str:
return await dao.save_new_invite(
dct=dict(inviter_id=inviter.id, type_=InviteType.promotion_confirm.name),
dct={"inviter_id": inviter.id, "type_": InviteType.promotion_confirm.name},
token_len=16,
)

Expand Down Expand Up @@ -287,10 +287,10 @@ async def merge_players(
await game_log.log(
GameLogEvent(
GameLogType.PLAYERS_MERGED,
dict(
primary=primary.name_mention,
secondary=secondary.name_mention,
),
{
"primary": primary.name_mention,
"secondary": secondary.name_mention,
},
)
)

Expand All @@ -303,7 +303,7 @@ async def merge_team_history(primary: dto.Player, secondary: dto.Player, dao: Pl
if primary_history[0].date_joined > secondary_history[0].date_joined:
merged = secondary_history
if not merged:
merged = list(sorted(primary_history + secondary_history, key=lambda tp: tp.date_joined))
merged = sorted(primary_history + secondary_history, key=lambda tp: tp.date_joined)
for tp1, tp2 in zip(merged[:-1:], merged[1::]):
if tp1.date_left is None or (tp1.date_left > tp2.date_joined):
raise ValueError("can't join automatically")
Expand Down
Loading

0 comments on commit 51df411

Please sign in to comment.