New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make pydantic errors (un)pickable #1630
fix: make pydantic errors (un)pickable #1630
Conversation
8a82658
to
81f58d7
Compare
Codecov Report
@@ Coverage Diff @@
## master #1630 +/- ##
=======================================
Coverage 99.94% 99.94%
=======================================
Files 21 21
Lines 3799 3803 +4
Branches 756 756
=======================================
+ Hits 3797 3801 +4
Misses 1 1
Partials 1 1
Continue to review full report at Codecov.
|
pydantic/errors.py
Outdated
@@ -101,6 +112,9 @@ def __init__(self, **ctx: Any) -> None: | |||
def __str__(self) -> str: | |||
return self.msg_template.format(**self.__dict__) | |||
|
|||
def __reduce__(self): # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelcolvin I thought ignoring typing made more sense for this one as it made the code more complicated for nothing.
But if you want me to, I can add this commit PrettyWood@753abdd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should include type hints if at all possible
I have verified that this PR fixes the bug I reported in #1616 Thanks @PrettyWood ! |
Oh, for the record.... I did not test the Cython version of pydantic with this PR applied. I couldn't figure out how that would be installed locally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise I think this looks good.
pydantic/errors.py
Outdated
@@ -91,6 +91,17 @@ | |||
) | |||
|
|||
|
|||
def cls_kwargs(cls, kwargs): # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def cls_kwargs(cls, kwargs): # type: ignore | |
def cls_kwargs(cls: Type[T], kwargs: Dict[str, Any) -> T: # type: ignore |
Or something?
Even if mypy can't handle it should still add type hints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, shouldn't this be cls_kwargs(cls, ctx)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would like this method to be more generic with Type[T]
and ctx
for args
and kwargs
? Sorry if I misunderstood
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean:
- we should have type annotations
- i think it would make more sense to name the second argument
ctx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright ! I added the annotations that I already linked and renamed kwargs
into ctx
.
pydantic/errors.py
Outdated
@@ -101,6 +112,9 @@ def __init__(self, **ctx: Any) -> None: | |||
def __str__(self) -> str: | |||
return self.msg_template.format(**self.__dict__) | |||
|
|||
def __reduce__(self): # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should include type hints if at all possible
Change Summary
Custom pydantic errors (subclasses of
PydanticTypeError
andPydanticValueError
) were not (un)pickable. Now they are!Related issue number
closes #1616
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)