Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Nov 24, 2024

Doing so fixes #10958 and gtalarico/pyairtable#411. We don't need to evaluate annotation for private fields because we will not make use of the type hint in any way.


The get_cls_type_hints function is now split up, by defining a new get_model_type_hints function that is lenient. get_cls_type_hints is made non-lenient because it is used for typed dictionaries and named tuples, where we want to eagerly raise the NameErrors that can occur during evaluation.

While this may introduce some code duplication, this gives more flexibility in the future. For instance, we know from the namespace management refactor that typed dicts behaves quite differently from normal classes when it comes to using the __annotations__ attribute (collected from bases by cpython, automatically converted to ForwardRef instances, etc). So we might define another separate get_typed_dict_type_hints function in the future.

Change Summary

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

Copy link

cloudflare-workers-and-pages bot commented Nov 24, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 213b274
Status: ✅  Deploy successful!
Preview URL: https://e420a41e.pydantic-docs.pages.dev
Branch Preview URL: https://private-fields-eval.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Nov 24, 2024

CodSpeed Performance Report

Merging #10962 will not alter performance

Comparing private-fields-eval (213b274) with main (15f693a)

Summary

✅ 46 untouched benchmarks

Copy link
Contributor

github-actions bot commented Nov 24, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _fields.py
  _generate_schema.py
  _typing_extra.py 506-507
Project Total  

This report was generated by python-coverage-comment-action

@Viicos Viicos force-pushed the private-fields-eval branch 2 times, most recently from 2d35039 to 76460e2 Compare November 24, 2024 17:56
@potiuk
Copy link

potiuk commented Nov 24, 2024

Nice!

@Viicos Viicos force-pushed the private-fields-eval branch from 76460e2 to 8446583 Compare November 24, 2024 20:00
The `get_cls_type_hints` function is now split up, by defining a
new `get_model_type_hints` function that is lenient.
`get_cls_type_hints` is made non-lenient because it is used for
typed dictionaries and named tuples, where we want to eagerly
raise the `NameError`s that can occur during evaluation.

While this may introduce some code duplication, this gives more
flexibility in the future. For instance, we know from the namespace
management refactor that typed dicts behaves quite differently from
normal classes when it comes to using the `__annotations__` attribute
(collected from bases by cpython, automatically converted to `ForwardRef`
instances, etc). So we might define another separate `get_typed_dict_type_hints`
function in the future.
@Viicos Viicos force-pushed the private-fields-eval branch from 8446583 to 213b274 Compare November 24, 2024 20:20
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.

Looks good, thanks @Viicos.

We might be able to reuse some shared logic between these functions in a future refactor, but the fix here is pretty simple, so I think we should get this across the line now 👍

@sydney-runkle sydney-runkle merged commit 2a8078a into main Nov 25, 2024
54 checks passed
@sydney-runkle sydney-runkle deleted the private-fields-eval branch November 25, 2024 15:19
potiuk added a commit to potiuk/airflow that referenced this pull request Nov 26, 2024
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not
needed any more as it has been fixed in Pydantic 2.10.2 in
the pydantic/pydantic#10962

This PR removes the workaround and bumps min Pydantic version to
2.10.2.
ferruzzi pushed a commit to apache/airflow that referenced this pull request Nov 26, 2024
The Pydantic 2.10.0/2.10.1 workaround implemented in #44317 is not
needed any more as it has been fixed in Pydantic 2.10.2 in
the pydantic/pydantic#10962

This PR removes the workaround and bumps min Pydantic version to
2.10.2.
ArshiaZr pushed a commit to ArshiaZr/airflow that referenced this pull request Nov 27, 2024
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not
needed any more as it has been fixed in Pydantic 2.10.2 in
the pydantic/pydantic#10962

This PR removes the workaround and bumps min Pydantic version to
2.10.2.
LefterisXefteris pushed a commit to LefterisXefteris/airflow that referenced this pull request Jan 5, 2025
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not
needed any more as it has been fixed in Pydantic 2.10.2 in
the pydantic/pydantic#10962

This PR removes the workaround and bumps min Pydantic version to
2.10.2.
got686-yandex pushed a commit to got686-yandex/airflow that referenced this pull request Jan 30, 2025
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not
needed any more as it has been fixed in Pydantic 2.10.2 in
the pydantic/pydantic#10962

This PR removes the workaround and bumps min Pydantic version to
2.10.2.
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request May 27, 2025
The Pydantic 2.10.0/2.10.1 workaround implemented in #44317 is not
needed any more as it has been fixed in Pydantic 2.10.2 in
the pydantic/pydantic#10962

This PR removes the workaround and bumps min Pydantic version to
2.10.2.

GitOrigin-RevId: b134ed089b74021858ded34dbc021ef053427650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing eval-type-backport as required dependency in 2.10.* Pydantic line for Python 3.8/3.9
3 participants