-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
⬆️ Update Pydantic v2 code to address deprecations #15101
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
Changes from all commits
5fe7833
94bd713
a1abbce
97ce5de
8e5d327
2d2fe3e
12f3db5
bbf1529
171f062
e867534
6851dad
f57b166
926156f
4f4491a
1f676f1
987f1d9
76f8b96
f3481b0
6c76442
f6c69a5
6646cb4
f7c8b7c
49cb386
c412722
53a6ee4
33b5930
381f567
5460dcc
d85b3dc
548d002
ed38f86
40fdef6
833ff83
e0e2568
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,3 +311,21 @@ class Model(BaseModel): | |
| def test_encode_pydantic_undefined(): | ||
| data = {"value": Undefined} | ||
| assert jsonable_encoder(data) == {"value": None} | ||
|
|
||
|
|
||
| @pytest.mark.filterwarnings("ignore::DeprecationWarning") | ||
| @pytest.mark.parametrize( | ||
| "module_path", | ||
| [ | ||
| pytest.param("pydantic.color"), | ||
| pytest.param("pydantic_extra_types.color"), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I took me some time to understand this comment 😅 Just to clarify if somebody also gets confused: it fails on |
||
| ], | ||
| ) | ||
| def test_encode_color(module_path): | ||
| try: | ||
| Color = __import__(module_path, fromlist=["Color"]).Color | ||
| except ImportError: # pragma: no cover | ||
| pytest.skip(f"{module_path} not available") | ||
|
|
||
| data = {"color": Color("blue")} | ||
| assert jsonable_encoder(data) == {"color": "blue"} | ||
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.
As an alternative, we can use
try...except:Or move this to module level, and only use it inside
evaluate_forwardref(so thatevaluate_forwardrefwould make it typed).It might also be a bit faster (but it's only used at app stratup, so maybe not as important)
Uh oh!
There was an error while loading. Please reload this page.
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.
Yea I think it's a style preference, I'm personally more fan of checking explicitely first rather than relying on a
try-except, but both are valid options. I'll leave it up to Sebastián to decide if he's got a preference 🙂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 found it a bit unfortunate that this PR still relies on an internal function.. The only reason I kept
eval_type_lenient()in Pydantic was because FastAPI was using it, and now the same issue exists withtry_eval_type().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.
@Viicos: right, good point. What would be the better way to address this? I can make a new PR.
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 it might be worth solving this cleanly, that is by first having the ability to do such evaluations using the stdlib. I proposed https://discuss.python.org/t/100698 a while ago, I'll try to continue working on it. Then we could see how can this be used in FastAPI/Pydantic!