Skip to content

Commit

Permalink
2025-01-10T18:34:51Z
Browse files Browse the repository at this point in the history
  • Loading branch information
wrmsr committed Jan 10, 2025
1 parent e2fe785 commit ffd88be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ominfra/clouds/aws/models/base.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions omlish/dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
)

from .utils import ( # noqa
is_immediate_dataclass,

maybe_post_init,

opt_repr,
Expand Down
9 changes: 9 additions & 0 deletions omlish/dataclasses/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__
Expand Down

0 comments on commit ffd88be

Please sign in to comment.