Skip to content

Commit

Permalink
Improve dataclass instance check (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted authored Jul 9, 2024
1 parent 0c0a8db commit a61de1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kpops/components/base_components/base_defaults_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from abc import ABC
from collections.abc import Hashable, Sequence
from dataclasses import asdict, is_dataclass
from dataclasses import asdict
from functools import cached_property
from pathlib import Path
from typing import Any, TypeVar
Expand All @@ -23,6 +23,7 @@
from kpops.component_handlers import ComponentHandlers
from kpops.config import KpopsConfig
from kpops.utils import cached_classproperty
from kpops.utils.dataclasses import is_dataclass_instance
from kpops.utils.dict_ops import (
generate_substitution,
update_nested,
Expand Down Expand Up @@ -181,7 +182,7 @@ def extend_with_defaults(cls, config: KpopsConfig, **kwargs: Any) -> dict[str, A
for k, v in kwargs.items():
if isinstance(v, pydantic.BaseModel):
kwargs[k] = v.model_dump(exclude_unset=True)
elif is_dataclass(v):
elif is_dataclass_instance(v):
kwargs[k] = asdict(v)

defaults_file_paths_ = get_defaults_file_paths(
Expand Down
5 changes: 5 additions & 0 deletions kpops/utils/dataclasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dataclasses import is_dataclass


def is_dataclass_instance(obj: object) -> bool:
return is_dataclass(obj) and not isinstance(obj, type)

0 comments on commit a61de1b

Please sign in to comment.