Skip to content

Incorrect format passed to __annotate__ function #125507

Closed as not planned
Closed as not planned
@sobolevn

Description

@sobolevn

Bug report

Consider this example:

class My:
    def __annotate__(format):
        assert format == 2, format
        return {}

import annotationlib
annotationlib.get_annotations(My, format=2)

This will fail with:

Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/ex.py", line 7, in <module>
    annotationlib.get_annotations(My, format=2)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/annotationlib.py", line 688, in get_annotations
    return dict(_get_dunder_annotations(obj))
                ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/annotationlib.py", line 817, in _get_dunder_annotations
    ann = _BASE_GET_ANNOTATIONS(obj)
  File "/Users/sobolev/Desktop/cpython2/ex.py", line 3, in __annotate__
    assert format == 2, format
           ^^^^^^^^^^^
AssertionError: 1

I think that we should still pass the format in _BASE_GET_ANNOTATIONS.

I will try to fix this, since this affects my other PR: #122262

CC @JelleZijlstra

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14new features, bugs and security fixesstdlibPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions