0.13.1 typing fixes

This commit is contained in:
Yusur 2026-06-20 17:26:07 +02:00
parent 73a9f68590
commit 82d4fc2ab2
7 changed files with 33 additions and 20 deletions

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.13.1
+ Typing fixes
## 0.13.0 "Laconic Letters" ## 0.13.0 "Laconic Letters"
+ Added module `argparse` with class `LetterSubparsers()`, which allows pacman-style args by preprocessing them + Added module `argparse` with class `LetterSubparsers()`, which allows pacman-style args by preprocessing them

View file

@ -41,7 +41,7 @@ from .color import OKLabColor, chalk, WebColor, RGBColor, LinearRGBColor, \
from .mat import Matrix from .mat import Matrix
from .argparse import LetterSubparsers from .argparse import LetterSubparsers
__version__ = "0.13.0" __version__ = "0.13.1"
__all__ = ( __all__ = (
'ColorFormatter', 'ColorFormatter',

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