From aa19e344f50dc4df9eb7050ff262017e06942776 Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Sat, 20 Jun 2026 17:26:07 +0200 Subject: [PATCH] 0.12.7 backport fixes from 0.13.1 --- CHANGELOG.md | 15 +++++++++++++++ src/suou/__init__.py | 2 +- src/suou/itertools.py | 38 ++++++++++++++++++++++++-------------- src/suou/lex.py | 2 -- src/suou/luck.py | 2 +- src/suou/markdown.py | 1 + src/suou/waiter.py | 4 ++-- 7 files changed, 44 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0734c65..91e5bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.13.1 and 0.12.7 + ++ Typing fixes + +## 0.13.0 "Laconic Letters" + ++ Added module `argparse` with class `LetterSubparsers()`, which allows pacman-style args by preprocessing them + before feeding them to parse_args ++ Module `sqlalchemy`: + * removed deprecated alias `entity_base()`. use `declarative_base()` instead. + * fix imports. ++ Module `functools`: add `cooldown()`, `do_not_flood()` ++ Module `color`: add `ColorFormatter()` ++ Separated `suou[waiter]` dependency from `suou[quart]` + ## 0.12.6 + Added unittests to `dei_args()` diff --git a/src/suou/__init__.py b/src/suou/__init__.py index 6a434e4..f6a04f8 100644 --- a/src/suou/__init__.py +++ b/src/suou/__init__.py @@ -38,7 +38,7 @@ from .http import WantsContentType from .color import OKLabColor, chalk, WebColor, RGBColor, LinearRGBColor, XYZColor, OKLCHColor from .mat import Matrix -__version__ = "0.12.6" +__version__ = "0.12.7" __all__ = ( 'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue', diff --git a/src/suou/itertools.py b/src/suou/itertools.py index 881e30a..9ec1e68 100644 --- a/src/suou/itertools.py +++ b/src/suou/itertools.py @@ -22,17 +22,13 @@ from suou.classtools import MISSING _T = TypeVar('_T') -def makelist(l: Any, wrap: bool = True) -> list | Callable[Any, list]: - ''' - Make a list out of an iterable or a single value. +def _makelist_callable(l: Callable) -> Callable[..., list]: + @wraps(l) + def wrapper(*a, **k): + return _makelist_nowrap(l(*a, **k)) + return wrapper - *Changed in 0.4.0* Now supports a callable: can be used to decorate generators and turn them into lists. - Pass wrap=False to return instead the unwrapped function in a list. - - *Changed in 0.11.0*: ``wrap`` argument is now no more keyword only. - ''' - if callable(l) and wrap: - return wraps(l)(lambda *a, **k: makelist(l(*a, **k), wrap=False)) +def _makelist_nowrap(l: Any) -> list: if isinstance(l, (str, bytes, bytearray)): return [l] elif isinstance(l, Iterable): @@ -42,7 +38,21 @@ def makelist(l: Any, wrap: bool = True) -> list | Callable[Any, list]: else: return [l] -def ltuple(seq: Iterable[_T], size: int, /, pad = None) -> tuple: +def makelist(l: Any, wrap: bool = True) -> list | Callable[..., list]: + ''' + Make a list out of an iterable or a single value. + + *Changed in 0.4.0* Now supports a callable: can be used to decorate generators and turn them into lists. + Pass wrap=False to return instead the unwrapped function in a list. + + *Changed in 0.11.0*: ``wrap`` argument is now no more keyword only. + ''' + if callable(l) and wrap: + return _makelist_callable(l) + else: + return _makelist_nowrap(l) + +def ltuple(seq: Iterable[_T], size: int, /, pad = None) -> tuple[_T, ...]: """ Truncate an iterable into a fixed size tuple, if necessary padding it. """ @@ -51,7 +61,7 @@ def ltuple(seq: Iterable[_T], size: int, /, pad = None) -> tuple: seq = seq + (pad,) * (size - len(seq)) return seq -def rtuple(seq: Iterable[_T], size: int, /, pad = None) -> tuple: +def rtuple(seq: Iterable[_T], size: int, /, pad = None) -> tuple[_T, ...]: """ Same as rtuple() but the padding and truncation is made right to left. """ @@ -81,7 +91,7 @@ def kwargs_prefix(it: dict[str, Any], prefix: str, *, remove = True, keep_prefix it.pop(k) return ka -def additem(obj: MutableMapping, /, name: str = None): +def additem(obj: MutableMapping, /, name: str | None = None): """ Syntax sugar for adding a function to a mapping, immediately. """ @@ -93,7 +103,7 @@ def additem(obj: MutableMapping, /, name: str = None): return func return decorator -def addattr(obj: Any, /, name: str = None): +def addattr(obj: Any, /, name: str | None = None): """ Same as additem() but setting as attribute instead. """ diff --git a/src/suou/lex.py b/src/suou/lex.py index 5655eea..6ad77a5 100644 --- a/src/suou/lex.py +++ b/src/suou/lex.py @@ -62,8 +62,6 @@ def symbol_table(*args: Iterable[tuple | TokenSym], whitespace: str | None = Non yield TokenSym('[' + re.escape(whitespace) + ']+', '', discard=True) -symbol_table: Callable[..., list] - def ilex(text: str, table: Iterable[TokenSym], *, whitespace = False): """ Return a text as a list of tokens, given a token table (iterable of TokenSym). diff --git a/src/suou/luck.py b/src/suou/luck.py index c4ec49e..4c808fa 100644 --- a/src/suou/luck.py +++ b/src/suou/luck.py @@ -35,7 +35,7 @@ def lucky(validators: Iterable[Callable[[_U], bool]] = ()): *New in 0.7.0* """ - def decorator(func: Callable[_T, _U]) -> Callable[_T, _U]: + def decorator(func: Callable[..., _U]) -> Callable[..., _U]: @wraps(func) def wrapper(*args, **kwargs) -> _U: try: diff --git a/src/suou/markdown.py b/src/suou/markdown.py index acd4ab5..09cac11 100644 --- a/src/suou/markdown.py +++ b/src/suou/markdown.py @@ -86,4 +86,5 @@ class PingExtension(markdown.extensions.Extension): md.inlinePatterns.register(MentionPattern(re.escape(at) + r'(' + self.CHARACTERS + ')', url_prefix), 'ping_mention', 14) +# Optional dependency: do not import into __init__.py __all__ = ('PingExtension', 'SpoilerExtension', 'StrikethroughExtension') diff --git a/src/suou/waiter.py b/src/suou/waiter.py index 9a5e3bd..7c55999 100644 --- a/src/suou/waiter.py +++ b/src/suou/waiter.py @@ -28,7 +28,7 @@ from suou.functools import future @future() class Waiter(): - _cached_app: Callable | None = None + _cached_app: Starlette | None = None def __init__(self): self.routes: list[Route] = [] @@ -60,7 +60,7 @@ class Waiter(): def patch(self, endpoint: str, *a, **k): return self._route('PATCH', endpoint, *a, **k) - def _route(self, methods: list[str], endpoint: str, **kwargs): + def _route(self, methods: str | list[str], endpoint: str, **kwargs): def decorator(func): self.routes.append(Route(endpoint, func, methods=makelist(methods, False), **kwargs)) return func