Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor_typing_extra module#10725

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

Merged
sydney-runkle merged 5 commits intomainfromrefactor-typing-extra
Nov 8, 2024
Merged

Conversation

Viicos
Copy link
Member

@ViicosViicos commentedOct 27, 2024
edited
Loading

Change Summary

  • Refactor the_typing_extra module to:
    • make use ofhttps://typing-extensions.readthedocs.io/en/latest/#runtime-use-of-types. In a lot of places, we are only checking forsome_obj is typing(_extensions).SomeType which can break at any time iftyping_extensions backports some changes from Python, in which casetyping.SomeType is not typing_extensions.SomeType.
    • Cleanup/simplify someis_* functions (e.g.is_newtype,is_classvar).
    • Add a newis_classvar_annotation function, that should be used in most cases. This function handlesClassVar being wrapped inAnnotated, and also stringified annotations.
    • Renameall_literal_values toliteral_values, replacing the unusedliteral_values function. When we drop support for Python 3.8, replace usage with a plainget_args.
    • Remove unecessaryis_dataclass function,dataclasses.is_dataclass provides a type guard return annotation.
  • Adapt the codebase to use the new constructs. In some cases, this does fix some actual bugs

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

@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelOct 27, 2024
@cloudflare-workers-and-pagesCloudflare Workers and Pages
Copy link

cloudflare-workers-and-pagesbot commentedOct 27, 2024
edited
Loading

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:5a43b8d
Status: ✅  Deploy successful!
Preview URL:https://b118d254.pydantic-docs.pages.dev
Branch Preview URL:https://refactor-typing-extra.pydantic-docs.pages.dev

View logs

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedOct 27, 2024
edited
Loading

CodSpeed Performance Report

Merging#10725 willnot alter performance

Comparingrefactor-typing-extra (5a43b8d) withmain (a25e028)

Summary

✅ 44 untouched benchmarks

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedOct 27, 2024
edited
Loading

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  dataclasses.py
  json_schema.py
  main.py
  pydantic/_internal
  _core_utils.py
  _dataclasses.py
  _fields.py
  _generate_schema.py
  _generics.py
  _model_construction.py
  _repr.py
  _std_types_schema.py
  _typing_extra.py35,199
Project Total 

This report was generated bypython-coverage-comment-action

@ViicosViicosforce-pushed therefactor-typing-extra branch 3 times, most recently from279daa8 toc68a904CompareOctober 29, 2024 07:55
@ViicosViicosforce-pushed therefactor-typing-extra branch 4 times, most recently froma5ef806 to088b5c2CompareOctober 30, 2024 08:44
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thisdisplay_as_type function needs to be refactored, as it is relatively expensive to recursively check forget_origin,get_args, etc. It is currently used:

  • InFieldInfo.__repr_args__, to make a string representation of theannotation attribute. This can be kept.
  • Inget_type_ref, called for each arg of a parametrized type. We should find a simpler way to generate a core schema reference.

sydney-runkle reacted with thumbs up emoji
@ViicosViicos marked this pull request as ready for reviewOctober 31, 2024 10:34
@sydney-runkle
Copy link
Contributor

Should we be concerned about some of the minor performance regressions we see for schema building here?

https://codspeed.io/pydantic/pydantic/branches/refactor-typing-extra

@Viicos
Copy link
MemberAuthor

Should we be concerned about some of the minor performance regressions we see for schema building here?

My assumption is that the small regression comes from the fact that in hot functions (display_as_type,get_type_ref,has_instance_in_type) we now properly check for the two variants (typing andtyping_extensions), e.g. forTypeAliasType.

I think the real problem is that we should find a way to avoid calling these functions so many times, this is what I'm working on currently as part of#10297

sydney-runkle reacted with thumbs up emoji

Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

Wow, nice work@Viicos. Things feel much cleaner in the internal type management department with this PR. Left some general feedback 👍

@@ -184,7 +184,7 @@ def _get_caller_frame_info(depth: int = 2) -> tuple[str | None, bool]:
DictValues: type[Any] = {}.values().__class__


def iter_contained_typevars(v: Any) -> Iterator[TypeVarType]:
def iter_contained_typevars(v: Any) -> Iterator[TypeVar]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain this change, briefly? Thanks!

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

TypeVarType was defined as an alias toAny as a workaround, because mypy could not understand something like this:

TypeVarType:TypeAlias=TypeVar

But for pyright (and maybe mypy as of today), it is perfectly fine to useTypeVar as type annotations, it behaves as any other type

Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

Nice, thanks for incorporating the feedback.

Happy to merge this now, given that we're going to see perf improvements bounce back up with#10769

@sydney-runklesydney-runkle merged commit5b7c290 intomainNov 8, 2024
55 checks passed
@sydney-runklesydney-runkle deleted the refactor-typing-extra branchNovember 8, 2024 14:19
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sydney-runklesydney-runklesydney-runkle approved these changes

Assignees
No one assigned
Labels
relnotes-fixUsed for bugfixes.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Viicos@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp