Compare commits

...

1 commit

Author SHA1 Message Date
aa19e344f5 0.12.7 backport fixes from 0.13.1 2026-06-20 17:31:54 +02:00
7 changed files with 44 additions and 20 deletions

View file

@ -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()`

View file

@ -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',

View file

@ -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.
"""

View file

@ -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).

View file

@ -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:

View file

@ -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')

View file

@ -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