I have a code with responsibility division:
- Standard classes which are getting they defenition (inherit) from a dataclasses.
- Dataclasses themselves.
How I can combine a default class with dataclass to get methods from class and "entity" (self definition) from a dataclass?
Currently I'm getting an error.
Code:
# data_classes.py
from dataclasses import dataclass
@dataclass(slots=True)
class User:
tg_user_id: int
@dataclass(slots=True)
class NewUser(User):
username: str
gender: str
age: int
location: str
comment: str
moto_drive_style: str
moto_type: str
moto_hp: int
moto_brand: str
#classes.py
import data_classes
class User(data_classes.User):
__slots__ = ('_cursor', 'last_function', )
def __init__(self, tg_user_id: int):
super().__init__(tg_user_id)
self._cursor = GLOBAL_CONNECTION.cursor()
self.last_function = None
def __repr__(self):
return {'tg_user_id': self.tg_user_id}
def _convert_profile_text(self) -> dict:
"""
Should be executed after db insertion
"""
# noinspection PyUnresolvedReferences
converted_data_with_none = {
# Don't forget to use parse_mode="HTML" if you are using links
'Имя': f"<a href='tg://user?id={self.tg_user_id}'>{self.username}</a>",
'Пол': self.gender,
'Возраст': self.age,
'Откуда': f'{self.country}, {self.city}',
'Комментарий': self.comment,
'Стиль вождения': self.moto_drive_style,
'Класс мототехники': self.moto_type,
'Лошадиные силы': self.moto_hp,
'Марка и модель': self.moto_brand,
}
return {k: v for k, v in converted_data_with_none.items() if str(None) not in str(v)}
def show_profile(self, show_to_id: int, ) -> MessageId:
...
class NewUser(User, data_classes.NewUser):
def __init__(self, tg_user_id: int):
super().__init__(tg_user_id)
...
Error:
class NewUser(User, data_classes.NewUser):
TypeError: multiple bases have instance lay-out conflict
python-BaseException