From ffd88bec096d6f907e67f118132a868de85368f0 Mon Sep 17 00:00:00 2001 From: wrmsr Date: Fri, 10 Jan 2025 13:34:51 -0500 Subject: [PATCH] 2025-01-10T18:34:51Z --- ominfra/clouds/aws/models/base.py | 4 ++-- omlish/dataclasses/__init__.py | 2 ++ omlish/dataclasses/utils.py | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ominfra/clouds/aws/models/base.py b/ominfra/clouds/aws/models/base.py index 029c1fc43..4e493020b 100644 --- a/ominfra/clouds/aws/models/base.py +++ b/ominfra/clouds/aws/models/base.py @@ -1,9 +1,9 @@ -import dataclasses as dc import typing as ta from omlish import cached from omlish import check from omlish import collections as col +from omlish import dataclasses as dc from omlish import lang @@ -73,7 +73,7 @@ def metadata(self) -> ta.Mapping[ta.Any, ta.Any]: @cached.function def fields(self) -> ta.Sequence[dc.Field]: - check.in_('__dataclass_fields__', self._cls.__dict__) + check.state(dc.is_immediate_dataclass(self._cls)) fls = dc.fields(self._cls) return fls # noqa diff --git a/omlish/dataclasses/__init__.py b/omlish/dataclasses/__init__.py index 059090f9c..27c6fbee2 100644 --- a/omlish/dataclasses/__init__.py +++ b/omlish/dataclasses/__init__.py @@ -91,6 +91,8 @@ ) from .utils import ( # noqa + is_immediate_dataclass, + maybe_post_init, opt_repr, diff --git a/omlish/dataclasses/utils.py b/omlish/dataclasses/utils.py index f21079498..1b9a821d5 100644 --- a/omlish/dataclasses/utils.py +++ b/omlish/dataclasses/utils.py @@ -4,6 +4,7 @@ import typing as ta from .. import check +from .impl.internals import FIELDS_ATTR from .impl.metadata import METADATA_ATTR from .impl.metadata import UserMetadata from .impl.params import DEFAULT_FIELD_EXTRAS @@ -17,6 +18,14 @@ ## +def is_immediate_dataclass(cls: type) -> bool: + check.isinstance(cls, type) + return FIELDS_ATTR in cls.__dict__ + + +## + + def maybe_post_init(sup: ta.Any) -> bool: try: fn = sup.__post_init__