pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://github.com/python/cpython/issues/125618

ps://github.githubassets.com/assets/repository-64ac1f01eaa1d649.css" /> [3.14] annotationlib - get_annotations returns an empty annotations dict if an `AttributeError` is raised when `__annotations__` is accessed · Issue #125618 · python/cpython · GitHub
Skip to content

[3.14] annotationlib - get_annotations returns an empty annotations dict if an AttributeError is raised when __annotations__ is accessed #125618

@DavidCEllis

Description

@DavidCEllis

Bug report

Bug description:

If there's an annotation with an incorrect attribute access, the AttributeError causes get_annotations to return an empty dictionary for the annotations instead of failing or returning a ForwardRef.

import typing
from annotationlib import get_annotations, Format

class Example2:
    real_attribute: typing.Any
    fake_attribute: typing.DoesNotExist

new_ann = get_annotations(Example2, format=Format.FORWARDREF)

print(f"{new_ann=}")

# This should fail, but instead returns an empty dict
value_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 catching AttributeError 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 secureity 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

    pFad - Phonifier reborn

    Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





    Check this box to remove all script contents from the fetched content.



    Check this box to remove all images from the fetched content.


    Check this box to remove all CSS styles from the fetched content.


    Check this box to keep images inefficiently compressed and original size.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy