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

Deprecate class Id and NewId class factory #5

Merged
merged 1 commit into from
Sep 4, 2023
Merged
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
9 changes: 7 additions & 2 deletions ddd_framework/domain/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from abc import ABC
from datetime import datetime
from typing import Any, Protocol, TypeVar
Expand Down Expand Up @@ -44,6 +45,8 @@ def from_raw_id(cls, raw_id: str | int) -> Id:

def NewId(name: str, base: type[Id] = Id) -> type[Id]:
"""Create a new identifier's type."""
warnings.warn('Id class will be removed in the next update', DeprecationWarning, stacklevel=2)

return make_class(name, attrs={}, bases=(base,))


Expand All @@ -55,6 +58,8 @@ def structure_id(value: Any, _klass: type[Id]) -> Id:

cattrs.register_structure_hook(Id, structure_id)

EntityId = Any


# endregion

Expand All @@ -64,11 +69,11 @@ def structure_id(value: Any, _klass: type[Id]) -> Id:
class Entity:
"""Represent an entity."""

id: Id | None = field(default=None)
id: EntityId | Id | None = field(default=None)

def __hash__(self) -> int:
# TODO: Fix "Item "None" of "Id | None" has no attribute "id""
return hash(self.id.id) # type: ignore
return hash(self.id.id) if isinstance(self.id, Id) else hash(self.id)


# endregion
Expand Down