Skip to content

Remove _type attribute #329

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

Merged
merged 1 commit into from
Jun 20, 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
14 changes: 0 additions & 14 deletions flow360/component/simulation/framework/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def _handle_file(cls, filename: str = None, **kwargs):
def __pydantic_init_subclass__(cls, **kwargs) -> None:
"""Things that are done to each of the models."""
super().__pydantic_init_subclass__(**kwargs) # Correct use of super
cls._add_type_field()
cls._generate_docstring()

"""Sets config for all :class:`Flow360BaseModel` objects.
Expand Down Expand Up @@ -439,19 +438,6 @@ def append(self, params: Flow360BaseModel, overwrite: bool = False):
if is_frozen is None or is_frozen is False:
self.__setattr__(key, value)

@classmethod
def _add_type_field(cls) -> None:
"""Automatically place "type" field with model name in the model field dictionary."""

# TODO: Check if this _type actually fulfill its goal(?)
tag_field = pd.fields.FieldInfo(
alias=TYPE_TAG_STR,
value=cls.__name__,
annotation=Literal[cls.__name__],
class_validators=None,
)
cls.model_fields[TYPE_TAG_STR] = tag_field

@classmethod
def _generate_docstring(cls) -> str:
"""Generates a docstring for a Flow360 model and saves it to the __doc__ of the class."""
Expand Down
2 changes: 0 additions & 2 deletions flow360/component/simulation/framework/cached_model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pydantic as pd

from flow360.component.simulation.framework.base_model import Flow360BaseModel
from flow360.component.types import TYPE_TAG_STR


class CachedModelBase(Flow360BaseModel, metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -40,7 +39,6 @@ def __init__(self, **data):
pass
else:
defaults = {name: field.default for name, field in self.model_fields.items()}
defaults.pop(TYPE_TAG_STR)
self._cached = self.__annotations__["_cached"](
**{**defaults, **data}, constructor="default"
)
Expand Down
5 changes: 0 additions & 5 deletions tests/simulation/framework/test_base_model_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ def test_from_json_yaml():
os.remove(temp_file_name)


def test_add_type_field():
## Note: May need to be properly implemented.
assert "_type" in BaseModelTestModel.model_fields


def test_generate_docstring():
assert "some_value" in BaseModelTestModel.__doc__

Expand Down
Loading