bug: Add annotation to ModelField for use in BaseModel.__signature__#3413
bug: Add annotation to ModelField for use in BaseModel.__signature__#3413samuelcolvin merged 9 commits intopydantic:masterfrom
Conversation
samuelcolvin
left a comment
There was a problem hiding this comment.
Seems good to me, but please add a change description.
I don't think this can go in v1.9.1 as it's not a bug fix for v1.9
|
please update. |
|
Hmm. While I am adding a public attribute, and that could be considered a feature, I am only doing it to fix what I would consider a bug (incorrect results from |
|
I don't mind the public attribute, I don't see another (simply) way. Which of my points were you questioning? The current description, out which release this goes in? |
|
I was just questioning if this is a bug fix or a feature. I think the underlying problem is a bug, but if we're adding a public attribute it's more like a feature. I'll add the change description. |
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
|
@samuelcolvin I guess we didn't merge this 😅 |
…pydantic into fix-annotated-optional
Got there in the end 😓. Thank so much, as ever, sorry for the delay. |
|
@samuelcolvin looks like this one won't auto-merge because of the old "request changes" - I think it'll need an approval to override. |
|
Thanks @JacobHayes, missed that. |
|
Yup, I missed the auto-merge announcement so excited to find it in the wild! |
|
Ye, it's been a god sent for this work. |
Currently,
ModelField.outer_type_is used forModel.__signature__.This leads to signatures that differ from dataclasses or classes with a manual
__init__of the same types.This PR fixes this by storing the annotation in
ModelField.annotationand then using that for the signature instead ofouter_type_.I realize this is adding a public attribute to
ModelField, and that it is not as simple as storing thetype_passed into the constructor (I tried to handle the case where the type is inferred from the default value, I think successfully), so this may not be the best solution, but it is the best I could come up with today.