-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Re-organize exports for new validators and serializers #5641
Conversation
Deploying with Cloudflare Pages
|
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'm totally in agreement about moving methods to the new modules that make sense, but I really don't think we can remove the methods from __init__.py
.
- I think knowing that everything in the public API can be imported from
pydantic
is really helpful - One line imports for pydantic use is much cleaner and simpler
- changing this now, especially when we're adding new recommended functions like
field_validator
will add a lot more churn to the migration
On balance I think this is one of those "correct" vs. "easy" decisions where I tend to lean towards easy and you tend to lean towards correct.
I think on this occasion we should revert that change.
The only exception to the "everything in __init__.py
" rule right now (definitely the only important one) is dataclass
- on this I think we should:
- re-export our version of
dataclass
- rename the
dataclasses
module topydantic_dataclasses
to avoid confusion with std-lib dataclasses module.
If we're going to export something via |
I think there is - some people might well want to work like from pydantic import validators
...
@validators.[tab completion] More to the point, to "no export from another module" would require all other pydantic modules to be made private, which seems a little ugly. |
please review (will solve conflicts) |
18dfb53
to
0abffeb
Compare
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 LGTM.
pydantic/decorators.py
Outdated
|
||
return dec | ||
|
||
|
||
@overload |
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.
root_validator
should surely move into validators.py
?
More generally can we remove this module, or move it to _internal
.
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 didn't move it because:
- Backwards compatibility with V1.
- We want to deprecate
@root_validator
anyway
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.
root_validator
and validator
where in class_validators.py
in V1, the logic for supporting imports from the old path is already supported.
I think we move them.
12600d4
to
96dbb1a
Compare
I have a fix for the above issues. Please don't push until I've pushed my fix - currently can't due to problems with GH. |
…validators and pydantic.serializers
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
523a29c
to
59707b7
Compare
Selected Reviewer: @samuelcolvin