-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
support postponed annotations and ForwardRef in python 3.7 #348
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #348 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 14 14
Lines 1824 1857 +33
Branches 356 364 +8
=====================================
+ Hits 1824 1857 +33 |
3cc22e7 to
1145ae4
Compare
3b7e2a9 to
5ff33cd
Compare
|
Humm, so 5 people ask for this or similar, but no one is willing to take 20 minutes and test it or give any feedback. Not a great reflection on the open source community. I guess I'll wait a couple more days and merge it. |
0280183 to
de9a834
Compare
|
Just ran into this issue, and found it works for me! Pydantic 0.18 from __future__ import annotations
from pydantic import BaseModel
class CalendarRule(BaseModel):
id: int
calendar: int
children: t.List[CalendarRule]the above no longer crashes when I import Thanks for your work on this! |
|
Thanks, great to hear. |
|
Works for me as well, although with a slight catch compared to @StephenBrown2 (Python 3.7.3rc1, Pydantic 0.23) I have this model : If I only add Obviously adding that piece of code just works 👍 I've had some little issues with the documentation regarding this feature though, for which I'm making an issue and a PR. |
|
great to hear it works, PR for docs very welcome. |
* add "strip = true" to release profile * bump
Change Summary
support postponed annotations in python 3.7
Related issue number
fix #234
partial solution use ofForwardReffor the model itself isn't yet supported. Since almost all of the field setup logic assumes the model already exists this will be much more complicatedForwardRefshould now be fully supported. If theForwardRefcan't evaluate when creating the Model you'll need to callModel.update_forward_refs()after it's been created.Also note that the Model will need to be defined in the root of the module so it's included in globals, this is a limitation of
get_type_hintsit could be fixed in future by implementing our own version ofget_type_hintsbut that's beyond the scope of this PR I think.Checklist
HISTORY.rsthas been updated#<number>@<whomever>