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

[3.14] annotationlib - get_annotations returns an empty annotations dict if anAttributeError is raised when__annotations__ is accessed #125618

Closed
Assignees
JelleZijlstra
Labels
3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@DavidCEllis

Description

@DavidCEllis

Bug report

Bug description:

If there's an annotation with an incorrect attribute access, theAttributeError causesget_annotations to return an empty dictionary for the annotations instead of failing or returning aForwardRef.

importtypingfromannotationlibimportget_annotations,FormatclassExample2:real_attribute:typing.Anyfake_attribute:typing.DoesNotExistnew_ann=get_annotations(Example2,format=Format.FORWARDREF)print(f"{new_ann=}")# This should fail, but instead returns an empty dictvalue_ann=get_annotations(Example2,format=Format.VALUE)print(f"{value_ann=}")string_ann=get_annotations(Example2,format=Format.STRING)print(f"{string_ann=}")

Output

new_ann={}value_ann={}string_ann={'real_attribute': 'typing.Any', 'fake_attribute': 'typing.DoesNotExist'}

I think this is due to_get_dunder_annotations catchingAttributeError and returning an empty dict, intended for static types but catching this by mistake.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14bugs 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-2025 Movatter.jp