Skip to content

inspect.getmro() fails with AttributeError for typing.Annotated #98233

@Dutcho

Description

@Dutcho

Bug report

A typehint Annotated[T, x] should be interpreted as its type T if not specially handled (see typing documentation).
However, inspect.getmro() fails on Annotated[T, x], while it succeeds on T:

import inspect
import typing

print(inspect.getmro(int))
# works and outputs (<class 'int'>, <class 'object'>)

AnnotatedInt = typing.Annotated[int, 'annotation']
print(inspect.getmro(AnnotatedInt))
# fails with AttributeError: __mro__

I think this is incorrect, and that any remediation more likely should be (generically) in typing.Annotated than (as special case) in inspect.getmro().

Your environment

This fails on all Python version that support Annotated: 3.9-3.11. Tested with 3.9.13, 3.10.4, 3.11.0rc2 on Windows 11.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions