I have two dataclasses inside bookmodel, one inherited from the other:
@dataclass(frozen=True)
class BookOrder:
category: str
name: str
color: str
price: int
volume: int
@dataclass(frozen=True)
class ClientOrder(BookOrder):
client_id: str
Then in another .py file, I need to init a ClientOrder instance using BookOrder:
from book_model import BookOrder
# ...
@dataclass
class Client:
id: str
def place_book_order(self, book_order: BookOrder):
# want to init a ClientOrder HERE!!!
Since BookOrder is NOT callable, I cannot pass self.id to it. I was wondering if there's an elegant way to achieve this?
Update
Guess what I am trying to ask is, is there any other way to initialize a ClientOrder using BookOrder other than the below method?
client_order=ClientOrder(book_order.categry, book_order.name, ..., self.client_id)
ClientOrdera class that has two members: aBookOrderinstance and aclient_id. They you can just pass both to theClientOrderinitializer to create a client order.BookOrderdoes not have input params likeClientOrderdoes right? So I guess what I mean by not callable is that we cannot pass aid/any other vars as parameters to add as attribute to BookOrder.place_client_orderwhich could be used to create a ClientOrder object?client_order=ClientOrder(book_order)I gotTypeError: __init__() missing 5 required positional arguments: 'name', 'color', 'price', 'volume', and 'client_id'. Does this mean I have to initialize it by specfing each attributes likeclient_order=ClientOrder(book_order.categry, book_order.name, ..., self.client_id)?