Skip to content

Instantly share code, notes, and snippets.

@Tishka17
Tishka17 / generated.py
Created February 21, 2026 10:58
diwire generated code
"""
Generated DI resolver module.
Generated by: diwire._internal.resolvers.assembly.renderer.ResolversAssemblyRenderer.get_providers_code
diwire version used for generation: 1.0.1
Generation configuration:
- root scope level: 1
- managed scopes: app:1, session:2, request:3, action:4, step:5
- graph has async specs: False
@Tishka17
Tishka17 / hybrid_container.py
Last active February 20, 2026 10:59
Dishka async-sync container. `aget` and `get` methods
from __future__ import annotations
import warnings
from asyncio import Lock
from collections.abc import Callable, MutableMapping
from contextlib import AbstractAsyncContextManager
from types import TracebackType
from typing import Any, TypeVar, cast, overload
from dishka.entities.component import DEFAULT_COMPONENT, Component
@Tishka17
Tishka17 / bench_dishka.py
Created February 20, 2026 09:17
benchmark with big graph
import time
from textwrap import dedent
from dishka import BaseScope, Provider, make_container, provide, Scope
from dishka.plotter import render_d2, render_mermaid
# class MyScope(BaseScope):
# APP = "app"
# REQUEST = "request"
MyScope = Scope
@Tishka17
Tishka17 / autodoc_sig_unpack.py
Created November 29, 2025 23:09
Sphinx: support unpacking the Unpack in signatures
from inspect import signature, Parameter
from typing import get_type_hints, Unpack, get_origin, get_args, TypedDict
class _ExampleTypedDict(TypedDict):
pass
TypedDictMeta = type(_ExampleTypedDict)
@Tishka17
Tishka17 / declmod.py
Last active July 31, 2025 09:11
Python declarative modules
import sys
import types
def module(cls):
class tmp(cls, types.ModuleType):
pass
tmp.__name__ = cls.__name__
instance = tmp(f"{cls.__module__}.{cls.__name__}")
@Tishka17
Tishka17 / idtype.py
Last active July 11, 2025 15:11
ID Type
from dataclasses import field, dataclass
class ID:
def __init__(self, value: int | None = None):
self.value = value
def set(self, value: int):
if self.value is not None:
raise ValueError("Value already exists")
@Tishka17
Tishka17 / converter.py
Created June 5, 2025 16:27
Env vars processing using adaptix
from dataclasses import dataclass
from typing import Any, TypedDict
from adaptix import Retort, CannotProvide, name_mapping, loader, Chain
from adaptix._internal.provider.loc_stack_filtering import LocStack, P
from adaptix._internal.provider.location import TypeHintLoc
from adaptix._internal.provider.shape_provider import InputShapeRequest
class ClassTOTD:
@Tishka17
Tishka17 / adaptix_protobuf.py
Created June 2, 2025 12:10
Protobuf to dataclass converstion.
from dataclasses import dataclass
from pathlib import Path
import grpc
from google._upb._message import FieldDescriptor
from adaptix import TypeHint
from adaptix._internal.conversion.facade.func import get_converter
from adaptix._internal.model_tools.definitions import (
InputShape, InputField, NoDefault, Param, ParamKind, OutputShape,
@Tishka17
Tishka17 / conftest.py
Last active January 3, 2026 19:26
Postgres template in fixtures
import importlib
import os
from typing import Iterator
import alembic.command
import alembic.config
import psycopg
import pytest
import pytest_asyncio
from sqlalchemy import NullPool
@Tishka17
Tishka17 / jwt.py
Created May 19, 2025 13:48
JwtIdProvider
class JwtIdProvider(IdentityProvider):
def __init__(self, jwk_uri: str, aud: str, context: ServicerContext) -> None:
self.jwks_client = PyJWKClient(jwk_uri)
self.aud = aud
self.context = context
async def get_user(self) -> User | None:
for header, value in self.context.invocation_metadata():
if header != "authorization":
continue