-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Deprecate accessing model_fields
and model_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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…tances Also reorder `BaseModel` members in API documentation.
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 Performance ReportMerging #11169 will not 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
Coverage reportClick to see where and how coverage changed
This report was generated by python-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 in test_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 👍
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 |
Change Summary
Fixes #10930.
Requires #11168, which defines the new deprecation class.
Related issue number
Checklist