Привет, Хабр, меня зовут Юрий, я уже год использую хайповый IoC-контейнер dishka
и хочу немного поделиться опытом эксплуатации.
Мой проект — движок для городской ночной поисковой игры «Схватка»
(вы могли играть в неё или в один из аналогов — «Энкаунтер» или «Дозоры»).
У нас в городе очень маленькое ламповое комьюнити, для которого я и написал
этот движок. По причине локальности (игроков — всего 50 человек),
я не буду давать ссылки на что-то,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FAILED [ 96%] | |
tests/unit/serialization/test_deserialize.py:24 (test_deserialize_game) | |
+ Exception Group Traceback (most recent call last): | |
| File "/home/bomzheg/PycharmProjects/Shvatka/.venv/lib64/python3.11/site-packages/_pytest/runner.py", line 341, in from_call | |
| result: Optional[TResult] = func() | |
| ^^^^^^ | |
| File "/home/bomzheg/PycharmProjects/Shvatka/.venv/lib64/python3.11/site-packages/_pytest/runner.py", line 262, in <lambda> | |
| lambda: ihook(item=item, **kwds), when=when, reraise=reraise | |
| ^^^^^^^^^^^^^^^^^^^^^^^^ | |
| File "/home/bomzheg/PycharmProjects/Shvatka/.venv/lib64/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__ |
We have some app and dishka container
from fastapi import FasAPI
from dishka.integrations.fastapi import Depends, inject, setup_dishka
router = APIRouter()
@router.get("/")
@inject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import BinaryIO | |
from zipfile import Path as ZipPath | |
def load_results(zip_file: BinaryIO): | |
zip_path = ZipPath(zip_file) | |
for unpacked_file in zip_path.iterdir(): | |
if not unpacked_file.is_file(): | |
continue | |
if unpacked_file.name == "results.json": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from typing import Callable, Any, Awaitable | |
from aiogram import Bot, Dispatcher, types, BaseMiddleware | |
from aiogram.filters import Command | |
from aiogram.fsm.state import StatesGroup, State | |
from aiogram.fsm.storage.memory import MemoryStorage | |
from aiogram.types import Message, InlineQuery, TelegramObject | |
from aiogram.types.error_event import ErrorEvent | |
from aiogram_dialog import Window, Dialog, DialogRegistry, DialogManager, StartMode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Column, Integer, BigInteger, UniqueConstraint | |
from sqlalchemy.orm import relationship | |
from .base import Base | |
class Message(Base): | |
__tablename__ = "messages" | |
__mapper_args__ = {"eager_defaults": True} | |
__table_args__ = ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.future import select | |
from sqlalchemy.ext.asyncio import AsyncSession | |
from typing import List, TypeVar, Type, Generic | |
from app.models.db.base import Base | |
Model = TypeVar('Model', Base, Base) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import typing | |
import pyrogram | |
from aiogram.types import User | |
from loguru import logger | |
from pyrogram import Client | |
from pyrogram.errors import RPCError, UsernameNotOccupied, FloodWait | |
from app import config |