This file contains 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
""" | |
This module provides functions for splitting an amount into coins using given denominations. | |
The problem of generating change for a given amount, also known as the vending machine change problem (a special case of the knapsack problem), involves finding all possible combinations of coins that add up to a given amount. | |
""" | |
import functools | |
def split_iter(amount: int, denominations: tuple[int]): | |
if not denominations or amount < 0: |
This file contains 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
""" | |
This module provides a declarative way to describe delay strategies for controlling the interval between repeated actions, such as retrying a network request. | |
There are two categories of strategies: | |
1. Root Strategies: These provide the base logic for calculating delay time. | |
- Linear: Increases delay time linearly. | |
- Exponential: Increases delay time exponentially. | |
2. Modifier Strategies: These adjust the delay time calculated by a root strategy. |
This file contains 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
# NOTE(zeronineseven): Heavily based on https://gist.github.com/denBot/4136279812f87819f86d99eba77c1ee0 | |
import asyncio | |
import contextlib | |
import json | |
from contextlib import AsyncExitStack | |
from pathlib import Path | |
from typing import AsyncContextManager, Protocol, AsyncIterator, Never | |
import win32event | |
import win32pipe |
This file contains 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 ctypes import windll, Structure, c_char, c_ushort, c_char_p, POINTER, c_int, WinError | |
from ctypes.wintypes import WORD | |
from typing import Literal, TypeAlias | |
__all__ = "test", | |
_ExtraInfo: TypeAlias = Literal["peername", "socket", "sockname"] | |
This file contains 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 types import SimpleNamespace | |
from typing import Any | |
__all__ = "NamespaceMeta", "Namespace" | |
class NamespaceMeta(type): | |
"""Provides namespacing infrastructure. | |
This metaclass provides an alternative (and hopefully more convenient) syntax for creating 'types.SimpleNamespace' | |
instances using 'class' syntax. |
This file contains 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 weakref | |
import inspect | |
from asyncio import Future | |
from typing import Any, Callable, TypeVar, Protocol, Awaitable, Generator | |
__all__ = "Listenable", "Signal", | |
_T = TypeVar("_T", covariant=True) | |
This file contains 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 operator as op | |
import sqlalchemy as sa | |
__all__ = "anyof_constraint", | |
def anyof_constraint(*cols, at_least_one: bool = False) -> sa.CheckConstraint: | |
if len(cols) < 2: | |
raise ValueError("At least 2 columns MUST be provided to create any-of constraint!") |
This file contains 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 TypeAlias, Type | |
from frozendict import frozendict | |
import sqlalchemy as sa | |
import sqlalchemy.types | |
import sqlalchemy.event | |
import sqlalchemy.schema | |
import sqlalchemy.sql.sqltypes | |
__all__ = "define_composite", "CreateComposite", "DropComposite" |
This file contains 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 contextlib | |
import inspect | |
from inspect import Parameter, Signature | |
from dataclasses import dataclass | |
from contextlib import AsyncExitStack, AbstractContextManager, AbstractAsyncContextManager | |
from typing import Callable, ParamSpec, TypeVar | |
__all__ = "Depends", "inject_and_run" |
This file contains 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 unittest.mock | |
from fastapi import FastAPI as _FastAPI, APIRouter as _APIRouter, routing | |
__all__ = "FastAPI", "APIRouter" | |
class APIRouter(_APIRouter): | |
def include_router(self, router, **kwargs) -> None: | |
prefix = kwargs.get("prefix", "") |
NewerOlder