From 3af9d6c9fb5e75a8ce9ed00fe5ce6f2c0564b81b Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Mon, 1 Dec 2025 10:23:59 +0100 Subject: [PATCH] 0.11.1 make `yesno()` accept boolean types --- CHANGELOG.md | 4 ++++ src/suou/__init__.py | 2 +- src/suou/validators.py | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0115b..d42d190 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.11.1 + ++ make `yesno()` accept boolean types + ## 0.11.0 + **Breaking**: sessions returned by `SQLAlchemy()` are now wrapped by default. Restore original behavior by passing `wrap=False` to the constructor or to `begin()` diff --git a/src/suou/__init__.py b/src/suou/__init__.py index 63b6d18..9097a9b 100644 --- a/src/suou/__init__.py +++ b/src/suou/__init__.py @@ -37,7 +37,7 @@ from .redact import redact_url_password from .http import WantsContentType from .color import chalk, WebColor -__version__ = "0.11.0" +__version__ = "0.11.1" __all__ = ( 'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue', diff --git a/src/suou/validators.py b/src/suou/validators.py index e8b366f..349172a 100644 --- a/src/suou/validators.py +++ b/src/suou/validators.py @@ -20,8 +20,6 @@ from typing import Any, Iterable, TypeVar from suou.classtools import MISSING -from .functools import future - _T = TypeVar('_T') def matches(regex: str | int, /, length: int = 0, *, flags=0): @@ -59,13 +57,24 @@ def not_less_than(y): """ return lambda x: x >= y -def yesno(x: str) -> bool: +def yesno(x: str | int | bool | None) -> bool: """ Returns False if x.lower() is in '0', '', 'no', 'n', 'false' or 'off'. *New in 0.9.0* + + *Changed in 0.11.1*: now accepts None and bool. """ - return x not in (None, MISSING) and x.lower() not in ('', '0', 'off', 'n', 'no', 'false', 'f') + if x in (None, MISSING): + return False + if isinstance(x, bool): + return x + if isinstance(x, int): + return x != 0 + if isinstance(x, str): + return x.lower() not in ('', '0', 'off', 'n', 'no', 'false', 'f') + return True + __all__ = ('matches', 'must_be', 'not_greater_than', 'not_less_than', 'yesno')