diff --git a/src/suou/__init__.py b/src/suou/__init__.py index 4a14073..9d12a76 100644 --- a/src/suou/__init__.py +++ b/src/suou/__init__.py @@ -27,7 +27,7 @@ from .itertools import makelist, kwargs_prefix, ltuple, rtuple, additem from .i18n import I18n, JsonI18n, TomlI18n from .snowflake import Snowflake, SnowflakeGen -__version__ = "0.4.0-dev26" +__version__ = "0.4.0-dev27" __all__ = ( 'Siq', 'SiqCache', 'SiqType', 'SiqGen', 'StringCase', diff --git a/src/suou/classtools.py b/src/suou/classtools.py index 34ad58b..6362b81 100644 --- a/src/suou/classtools.py +++ b/src/suou/classtools.py @@ -18,13 +18,19 @@ from __future__ import annotations from abc import ABCMeta, abstractmethod from typing import Any, Callable, Generic, Iterable, Mapping, TypeVar +import logging from suou.codecs import StringCase _T = TypeVar('_T') +logger = logging.getLogger(__name__) + MISSING = object() +def _not_missing(v) -> bool: + return v and v is not MISSING + class Wanted(Generic[_T]): """ Placeholder for parameters wanted by Incomplete(). @@ -106,6 +112,8 @@ class Incomplete(Generic[_T]): return clsdict +## Base classes for declarative argument / option parsers below + class ValueSource(Mapping): """ Abstract value source. @@ -158,6 +166,10 @@ class ValueProperty(Generic[_T]): for srckey, src in self._srcs.items(): if (getter := self._getter(obj, srckey)): v = getter.get(src, v) + if _not_missing(v): + if srckey != 'default': + logger.info(f'value {self._name} found in {srckey} source') + break if self._required and (not v or v is MISSING): raise self._not_found(f'required config {self._srcs['default']} not set!') if v is MISSING: