fix bug with multiple sources in classtools

This commit is contained in:
Yusur 2025-07-09 16:17:26 +02:00
parent 4919edc871
commit 9c3755637a
2 changed files with 13 additions and 1 deletions

View file

@ -27,7 +27,7 @@ from .itertools import makelist, kwargs_prefix, ltuple, rtuple, additem
from .i18n import I18n, JsonI18n, TomlI18n from .i18n import I18n, JsonI18n, TomlI18n
from .snowflake import Snowflake, SnowflakeGen from .snowflake import Snowflake, SnowflakeGen
__version__ = "0.4.0-dev26" __version__ = "0.4.0-dev27"
__all__ = ( __all__ = (
'Siq', 'SiqCache', 'SiqType', 'SiqGen', 'StringCase', 'Siq', 'SiqCache', 'SiqType', 'SiqGen', 'StringCase',

View file

@ -18,13 +18,19 @@ from __future__ import annotations
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from typing import Any, Callable, Generic, Iterable, Mapping, TypeVar from typing import Any, Callable, Generic, Iterable, Mapping, TypeVar
import logging
from suou.codecs import StringCase from suou.codecs import StringCase
_T = TypeVar('_T') _T = TypeVar('_T')
logger = logging.getLogger(__name__)
MISSING = object() MISSING = object()
def _not_missing(v) -> bool:
return v and v is not MISSING
class Wanted(Generic[_T]): class Wanted(Generic[_T]):
""" """
Placeholder for parameters wanted by Incomplete(). Placeholder for parameters wanted by Incomplete().
@ -106,6 +112,8 @@ class Incomplete(Generic[_T]):
return clsdict return clsdict
## Base classes for declarative argument / option parsers below
class ValueSource(Mapping): class ValueSource(Mapping):
""" """
Abstract value source. Abstract value source.
@ -158,6 +166,10 @@ class ValueProperty(Generic[_T]):
for srckey, src in self._srcs.items(): for srckey, src in self._srcs.items():
if (getter := self._getter(obj, srckey)): if (getter := self._getter(obj, srckey)):
v = getter.get(src, v) 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): if self._required and (not v or v is MISSING):
raise self._not_found(f'required config {self._srcs['default']} not set!') raise self._not_found(f'required config {self._srcs['default']} not set!')
if v is MISSING: if v is MISSING: