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 # 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 ## 0.12.6
+ Added unittests to `dei_args()` + 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 .color import OKLabColor, chalk, WebColor, RGBColor, LinearRGBColor, XYZColor, OKLCHColor
from .mat import Matrix from .mat import Matrix
__version__ = "0.12.6" __version__ = "0.12.7"
__all__ = ( __all__ = (
'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue', 'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue',

View file

@ -22,17 +22,13 @@ from suou.classtools import MISSING
_T = TypeVar('_T') _T = TypeVar('_T')
def makelist(l: Any, wrap: bool = True) -> list | Callable[Any, list]: def _makelist_callable(l: Callable) -> Callable[..., list]:
''' @wraps(l)
Make a list out of an iterable or a single value. 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. def _makelist_nowrap(l: Any) -> list:
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))
if isinstance(l, (str, bytes, bytearray)): if isinstance(l, (str, bytes, bytearray)):
return [l] return [l]
elif isinstance(l, Iterable): elif isinstance(l, Iterable):
@ -42,7 +38,21 @@ def makelist(l: Any, wrap: bool = True) -> list | Callable[Any, list]:
else: else:
return [l] 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. 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)) seq = seq + (pad,) * (size - len(seq))
return 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. 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) it.pop(k)
return ka 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. Syntax sugar for adding a function to a mapping, immediately.
""" """
@ -93,7 +103,7 @@ def additem(obj: MutableMapping, /, name: str = None):
return func return func
return decorator 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. 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) yield TokenSym('[' + re.escape(whitespace) + ']+', '', discard=True)
symbol_table: Callable[..., list]
def ilex(text: str, table: Iterable[TokenSym], *, whitespace = False): def ilex(text: str, table: Iterable[TokenSym], *, whitespace = False):
""" """
Return a text as a list of tokens, given a token table (iterable of TokenSym). 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* *New in 0.7.0*
""" """
def decorator(func: Callable[_T, _U]) -> Callable[_T, _U]: def decorator(func: Callable[..., _U]) -> Callable[..., _U]:
@wraps(func) @wraps(func)
def wrapper(*args, **kwargs) -> _U: def wrapper(*args, **kwargs) -> _U:
try: 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) 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') __all__ = ('PingExtension', 'SpoilerExtension', 'StrikethroughExtension')

View file

@ -28,7 +28,7 @@ from suou.functools import future
@future() @future()
class Waiter(): class Waiter():
_cached_app: Callable | None = None _cached_app: Starlette | None = None
def __init__(self): def __init__(self):
self.routes: list[Route] = [] self.routes: list[Route] = []
@ -60,7 +60,7 @@ class Waiter():
def patch(self, endpoint: str, *a, **k): def patch(self, endpoint: str, *a, **k):
return self._route('PATCH', endpoint, *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): def decorator(func):
self.routes.append(Route(endpoint, func, methods=makelist(methods, False), **kwargs)) self.routes.append(Route(endpoint, func, methods=makelist(methods, False), **kwargs))
return func return func