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

Support usage oftype withtyping.Self and type aliases#10621

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
Viicos merged 19 commits intopydantic:mainfromkc0506:fix-type-of-self
Oct 17, 2024

Conversation

kc0506
Copy link
Contributor

@kc0506kc0506 commentedOct 14, 2024
edited
Loading

Change Summary

Fix errors caused by these:

TypeAdapter(type[Self])typeMyInt=intTypeAdapter(type[MyInt])

Related issue number

fix#10618

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 14, 2024
@kc0506kc0506 changed the titleFix error caused bytype[Self]Fix error caused bytype[Self]; add typecheck fortype[]Oct 14, 2024
@kc0506kc0506 changed the titleFix error caused bytype[Self]; add typecheck fortype[]Fix error caused bytype[Self]; check the content oftype[] is a classOct 14, 2024
@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedOct 14, 2024
edited
Loading

CodSpeed Performance Report

Merging#10621 willnot alter performance

Comparingkc0506:fix-type-of-self (12a9c26) withmain (7bb0e0a)

Summary

✅ 44 untouched benchmarks

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedOct 14, 2024
edited
Loading

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _generate_schema.py1698
Project Total 

This report was generated bypython-coverage-comment-action

@kc0506kc0506 changed the titleFix error caused bytype[Self]; check the content oftype[] is a classFix error caused bytype[Self] andtype[TypeAliasType(...)]Oct 14, 2024
@kc0506kc0506 changed the titleFix error caused bytype[Self] andtype[TypeAliasType(...)]Fix errors generating schemas oftype[Self] andtype[TypeAliasType(...)]Oct 14, 2024
Copy link
Member

@ViicosViicos left a comment

Choose a reason for hiding this comment

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

Thanks for looking at this!

@ViicosViicos changed the titleFix errors generating schemas oftype[Self] andtype[TypeAliasType(...)]Support usage oftype withtyping.Self and type aliasesOct 14, 2024
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
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.

Looking good, nice work on the tests.

Wanted to resolve some questions about the_typing_extra.eval_type call - perhaps we could jump right to a type alias schema if one is detected...

@kc0506
Copy link
ContributorAuthor

kc0506 commentedOct 16, 2024
edited
Loading

I tried this snippet in Python 3.8, 3.10 and 3.12. Something interesting happed.

tp=List['int']tp_eval=typing._eval_type(tp,globals(),locals())print(typing.get_args(tp))print(typing.get_args(tp_eval))tp=list['int']tp_eval=typing._eval_type(tp,globals(),locals())print(typing.get_args(tp))print(typing.get_args(tp_eval))

The results are:

Python versionArgs ofList['int']Args ofList['int'], evaledArgs oflist['int']Args oflist['int'], evaled
3.8ForwardRef('int')intN.A.N.A.
3.9-3.11ForwardRef('int')int'int''int'
3.12ForwardRef('int')intForwardRef('int')int

So this means (only?) when user annotate withlist['int'] in Python 3.9-3.11, we will encounterstr instead ofForwardRef.

@Viicos
Copy link
Member

So this means (only?) when user annotate withlist['int'] in Python 3.9-3.11, we will encounterstr instead ofForwardRef.

This was done inpython/cpython#30900.

kc0506 reacted with thumbs up emoji

Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Copy link
Member

@ViicosViicos left a comment

Choose a reason for hiding this comment

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

Thanks!

@ViicosViicos merged commitf0002fc intopydantic:mainOct 17, 2024
61 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sydney-runklesydney-runklesydney-runkle left review comments

@ViicosViicosViicos 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.

type[Self] raises TypeError in pydantic-core
3 participants
@kc0506@Viicos@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp