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

ForwardRef: remove__hash__ and__eq__ #129463

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancement
@JelleZijlstra

Description

@JelleZijlstra

Feature or enhancement

Currently,annotationlib.ForwardRef has a__hash__ and__eq__ method, which look at a few attributes:

def__eq__(self,other):
(3.13). These look unsound already; it's possible for two ForwardRefs to compare equal but hash differently (if they have the same evaluated value but not the same__forward_module__). This gets worse on 3.14, where ForwardRef has gained a few more fields (
def__eq__(self,other):
).

I think it's better to remove the__eq__ and__hash__ methods fromForwardRef objects, and make it so two ForwardRefs are equal only if they're identical. I don't see a good use case for comparing two ForwardRefs for equality; if you want to know that they refer to the same thing, you should evaluate them and compare the type object that comes out.

This came up inagronholm/typeguard#492 where the current implementation of equality caused some grief. cc people involved with some runtime type checking tools:@agronholm@Viicos@leycec.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp