Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Deprecate accessingmodel_fields
andmodel_computed_fields
on instances#11169
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…tancesAlso reorder `BaseModel` members in API documentation.
cloudflare-workers-and-pagesbot commentedDec 21, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Deploying pydantic-docs with |
Latest commit: | b871688 |
Status: | ✅ Deploy successful! |
Preview URL: | https://7a2dc613.pydantic-docs.pages.dev |
Branch Preview URL: | https://10930.pydantic-docs.pages.dev |
codspeed-hqbot commentedDec 21, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#11169 willnot alter performanceComparing Summary
|
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.
The style guide flagged several spelling errors that seemed like false positives. We skipped posting inline suggestions for the following words:
- [Mm]odel_fields
github-actionsbot commentedDec 21, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Coverage reportClick to see where and how coverage changed
This report was generated bypython-coverage-comment-action |
@@ -814,26 +814,3 @@ def my_field_serializer(self, value: Any, info: FieldSerializationInfo) -> Any: | |||
return f'{info.field_name} = {value}' | |||
assert MyModel().model_dump() == {'my_field': 'my_field = foo', 'other_field': 'other_field = 42'} | |||
def test_fields_on_instance_and_cls() -> None: |
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.
Tested intest_deprecated.py
@@ -34,5 +34,6 @@ class Knight(BaseModel): | |||
assert_type(Knight.model_fields, dict[str, FieldInfo]) | |||
assert_type(Knight.model_computed_fields, dict[str, ComputedFieldInfo]) | |||
assert_type(k.model_fields, dict[str, FieldInfo]) | |||
assert_type(k.model_computed_fields, dict[str, ComputedFieldInfo]) | |||
# Mypy does not report the deprecated access (https://github.com/python/mypy/issues/18323): |
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.
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.
This looks good to me overall. Surprised that we had so many tests accessing these attributes on instances :(.
I've requested a few wording changes + maybe a chance to the already deprecated__fields__
as well.
I'd like to get input from@samuelcolvin on this PR before we merge, we can chat about this in our next sync 👍
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
Thought about this a bit more. I definitely think this makes sense to deprecate.
We haven't lost any functionality here, so I'm alright with going ahead and merging. I don't think@samuelcolvin would object to a simple deprecation here.
Yes to be clear, this was already deprecated by#10493, but this goes one step further by actually raising the deprecation warning and type checking error |
cfd4c9f
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Change Summary
Fixes#10930.
Requires#11168, which defines the new deprecation class.
Related issue number
Checklist