0.11.1 make yesno() accept boolean types
This commit is contained in:
parent
0460062867
commit
3af9d6c9fb
3 changed files with 18 additions and 5 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.11.1
|
||||||
|
|
||||||
|
+ make `yesno()` accept boolean types
|
||||||
|
|
||||||
## 0.11.0
|
## 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()`
|
+ **Breaking**: sessions returned by `SQLAlchemy()` are now wrapped by default. Restore original behavior by passing `wrap=False` to the constructor or to `begin()`
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ from .redact import redact_url_password
|
||||||
from .http import WantsContentType
|
from .http import WantsContentType
|
||||||
from .color import chalk, WebColor
|
from .color import chalk, WebColor
|
||||||
|
|
||||||
__version__ = "0.11.0"
|
__version__ = "0.11.1"
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue',
|
'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue',
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ from typing import Any, Iterable, TypeVar
|
||||||
|
|
||||||
from suou.classtools import MISSING
|
from suou.classtools import MISSING
|
||||||
|
|
||||||
from .functools import future
|
|
||||||
|
|
||||||
_T = TypeVar('_T')
|
_T = TypeVar('_T')
|
||||||
|
|
||||||
def matches(regex: str | int, /, length: int = 0, *, flags=0):
|
def matches(regex: str | int, /, length: int = 0, *, flags=0):
|
||||||
|
|
@ -59,13 +57,24 @@ def not_less_than(y):
|
||||||
"""
|
"""
|
||||||
return lambda x: x >= 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'.
|
Returns False if x.lower() is in '0', '', 'no', 'n', 'false' or 'off'.
|
||||||
|
|
||||||
*New in 0.9.0*
|
*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')
|
__all__ = ('matches', 'must_be', 'not_greater_than', 'not_less_than', 'yesno')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue