from dataclasses import dataclass, asdict
from json import dumps
def convert_snakecase_to_camelcase(name: str) -> str:
first, *rest = name.split("_")
return first + "".join(word.capitalize() for word in rest)
@dataclass(eq=False)
class UserConnection:
user_agent: str = None
ip: str = None
url: str = None
connected_at: str = None
user_platform_type: str = None
def export_as_model(self):
return asdict(self, dict_factory=self.camel_case_dict_factory)
@staticmethod
def camel_case_dict_factory(args: list) -> dict:
new_dict = {}
for key, value in args:
new_dict[convert_snakecase_to_camelcase(key)] = value
return new_dict
if __name__ == '__main__':
print(dumps(
UserConnection(*(('test',) * 5)).export_as_model(),
indent=4
))
{
"userAgent": "test",
"ip": "test",
"url": "test",
"connectedAt": "test",
"userPlatformType": "test"
}
x = 10
def test()
return range(x)
приводите полный трейс ошибки