Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dataclass instance check #507

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading