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

gh-90527: Evaluate typing.ForwardRef inside typing.NewType#91637

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

Open
uriyyo wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromuriyyo:fix-issue-90527

Conversation

uriyyo
Copy link
Member

@uriyyouriyyo commentedApr 17, 2022
edited by AlexWaygood
Loading

@JelleZijlstra
Copy link
Member

I think this will cause more trouble. NewTypes should generally be compared by identity, so creating a new one is problematic. I don't have a better idea though.

@uriyyo
Copy link
MemberAuthor

I think this will cause more trouble. NewTypes should generally be compared by identity, so creating a new one is problematic. I don't have a better idea though.

@JelleZijlstra I think we can mutate__supertype__ attr ofNewType. So impl will look like this:

ifisinstance(t,NewType):arg=ForwardRef(t.__supertype__)ifisinstance(t.__supertype__,str)elset.__supertype__t.__supertype__=_eval_type(arg,globalns,localns,recursive_guard)returnt

What do you think about such option?

@JelleZijlstra
Copy link
Member

JelleZijlstra commentedApr 17, 2022
edited
Loading

That's also problematic:

  1. It's nice to keep all typing objects immutable, since mutable state is the root of much evil.
  2. Theglobalns andlocalns in your code sample come from a specific call toget_type_hints. What if I callget_type_hints again later with a different namespace?

@uriyyo
Copy link
MemberAuthor

Possible solution can be add__eq__ implementation totyping.NewType. But it will go against identity compare.

@JelleZijlstraJelleZijlstra removed their request for reviewApril 18, 2022 00:19
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.11only security fixes labelMay 20, 2022
@AlexWaygoodAlexWaygood added needs backport to 3.12only security fixes and removed needs backport to 3.10only security fixes labelsJun 6, 2023
@serhiy-storchakaserhiy-storchaka added needs backport to 3.13bugs and security fixes and removed needs backport to 3.11only security fixes labelsMay 9, 2024
@tomasr8tomasr8 removed the needs backport to 3.12only security fixes labelApr 10, 2025
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.14bugs and security fixes labelMay 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gvanrossumgvanrossumAwaiting requested review from gvanrossum

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-Spinner

Assignees
No one assigned
Labels
awaiting reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesstdlibPython modules in the Lib dirtopic-typing
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@uriyyo@JelleZijlstra@serhiy-storchaka@tomasr8@bedevere-bot@AlexWaygood

[8]ページ先頭

©2009-2025 Movatter.jp