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

Python 3.14.1+ annotationlib regression: ForwardRef.__hash__ raisesTypeError: unhashable type: 'cell' #143831

Closed
Assignees
johnslavik
Labels
3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@abhinand-c

Description

@abhinand-c

Bug report

Bug description:

This issue was originally reported in thebeartype library (Ref:beartype/beartype#610), but investigation suggests it may stem from a change in Python’sannotationlib.ForwardRef implementation.

Starting with Python 3.14.1, deferred annotations (PEP 649) involving self-referential return type is raising:TypeError: unhashable type: 'cell' at decoration time.This worked correctly in Python 3.14.0 and the issue appears to persist in 3.14.2, suggesting a regression.

The error originates fromannotationlib.ForwardRef.__hash__, which attempts to hash internal state containing non-hashable cell objects. Although observed via beartype, this may affects any downstream library that hashes ForwardRef objects. The following code seems to be raising the issue:
tuple(sorted(self.__cell__.items())) if isinstance(self.__cell__, dict) else self.__cell__,

def__hash__(self):
returnhash((
self.__forward_arg__,
self.__forward_module__,
id(self.__globals__),# dictionaries are not hashable, so hash by identity
self.__forward_is_class__,
tuple(sorted(self.__cell__.items()))ifisinstance(self.__cell__,dict)elseself.__cell__,
self.__owner__,
tuple(sorted(self.__extra_names__.items()))ifself.__extra_names__elseNone,
))


Code:

#!pip install beartype==0.22.9frombeartypeimportbeartypeclassMyClass:@beartypedeffoo(self)->MyClass:returnMyClass()print(MyClass().foo())

Observed behavior:

The program fails during decoration with the error:TypeError: unhashable type: 'cell'

File".../beartype/_check/metadata/hint/hintsane.py", line 242,in __init__    self._hash = hash((hint, hint_recursable_to_depth, typearg_to_hint))File".../python3.14/annotationlib.py", line 291,in __hash__return hash((..., tuple(sorted(self.__extra_names__.items()))))TypeError: unhashable type:'cell'

Inspection shows:

>>>self.__cell__{'__classdict__':<cellat0x...:dictobject>}>>>tuple(sorted(self.__cell__.items()))(('__classdict__',<cellat0x...>),)

Since cell objects are not hashable, this causeshash to fail.

Affected Versions:

Python3.14.1 and3.14.2
OS Tested on: MacOS

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2026 Movatter.jp