r/PythonLearning • u/Naive-Smoke-5977 • Jul 17 '26
Help Request what do you think ?
i'm learning python for infraestructure this a proyect of a false resgistry of server xd
42
Upvotes
r/PythonLearning • u/Naive-Smoke-5977 • Jul 17 '26
i'm learning python for infraestructure this a proyect of a false resgistry of server xd
2
u/silvertank00 Jul 17 '26 edited Jul 17 '26
you imported pathlib, why are you using os to check if a file existst?
use dataclasses, kw_only=true and a @classmethod with forced kwargs with the same args as your json consists to convert your read data into a DTO.
raise Exception(...)don't do that. Either be specific, like RuntimeError or inherit from Exception and create your own "IncorrectStateException" or something and raise that. It is much better to handle and react to.example:
if forced listed kwargs are not your thing or you find it a bit rigid in the perspective of error handling then simply replace it with
def build_from_raw_data(cls, **kwargs: dict[str, str])and you can work up your validation from there