Closed AdrienVannson closed 2 months ago
Thanks! The problem that I had was that if I set optional = True
, the packages were not installed... but it should be possible somehow since it was how it was done before. I will have a look tomorrow
It is fixed now :)
Thank you
Summary
Python's dataclass prevent the user from creating instances of a dataclass with invalid fields (see the test that I added). However, this is not the case by default with Pydantic: the invalid fields are just removed from the message ( https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.extra ).
This can be the cause of errors if there is a typo in the name of a parameter. For this reason, I think it is better to add
config={"extra": "forbid"}
to pydantic dataclasses so that aValidationError
is raised in such a situation.To avoid adding type checking errors (this parameter does not exist in python's dataclasses), I had to remove the
if TYPE_CHECKING
condition that was used to import Python's dataclass instead. I updatedmypy
to its last version to avoid having the bug mentionned in https://github.com/danielgtaylor/python-betterproto/pull/460 . To do this, it was needed to remove support for python 3.7... but I think it is fine given the fact that the tests are no longer run with this python version, which is very old anyway. This also has the benefit of making the code a bit more clear.One point I am not completely sure about: I had to remove
optional = true
forblack
,jinja
andisort
inpyproject.toml
in order to be able to execute the tests... I'm not sure why it used to work before.Checklist