Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Dec 21, 2024

Change Summary

Fixes #10930.
Requires #11168, which defines the new deprecation class.

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

…tances

Also reorder `BaseModel` members in API documentation.
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Dec 21, 2024
Copy link

cloudflare-workers-and-pages bot commented Dec 21, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: b871688
Status: ✅  Deploy successful!
Preview URL: https://7a2dc613.pydantic-docs.pages.dev
Branch Preview URL: https://10930.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Dec 21, 2024

CodSpeed Performance Report

Merging #11169 will not alter performance

Comparing 10930 (b871688) with main (d823d8c)

Summary

✅ 46 untouched benchmarks

Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a 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

Copy link
Contributor

github-actions bot commented Dec 21, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  main.py
  pydantic/_internal
  _utils.py
Project Total  

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:
Copy link
Member Author

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

@Viicos Viicos added relnotes-change Used for changes to existing functionality which don't have a better categorization. and removed relnotes-fix Used for bugfixes. labels Dec 23, 2024
@@ -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):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@sydney-runkle sydney-runkle left a 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 👍

@pydantic-hooky pydantic-hooky bot added awaiting author revision awaiting changes from the PR author labels Dec 27, 2024
Copy link
Contributor

@sydney-runkle sydney-runkle left a 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.

@Viicos
Copy link
Member Author

Viicos commented Dec 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting author revision awaiting changes from the PR author relnotes-change Used for changes to existing functionality which don't have a better categorization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For v2.11: use custom decorator for model_fields and model_computed_fields
2 participants