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

inspect.get_annotations(eval_str=True) raisesSyntaxError for PEP-646 unpacked tuple annotation*tuple[...] #138891

Open
Labels
stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@artemyefimov

Description

@artemyefimov

Bug report

Bug description:

Problem

inspect.get_annotations(eval_str=True) raises aSyntaxError when evaluating unpacked tuple annotations (*tuple[...]):

from __future__importannotationsfrominspectimportget_annotationsdeff(*args:*tuple[int, ...]): ...print(get_annotations(f,eval_str=True))# Raises SyntaxError

The error occurs because*tuple[int, ...] is not a valid standalone expression foreval().

Expected

According totyping spec,*tuple[...] is valid in this context.

typing.get_type_hints already normalizes such annotations:

from __future__importannotationsfromtypingimportget_type_hintsdeff(*args:*tuple[int, ...]): ...print(get_type_hints(f))# {'args': typing.Unpack[tuple[int, ...]]}

inspect.get_annotations should behave consistently and not raiseSyntaxError.

Possible Resolution

Makeinspect.get_annotations(eval_str=True) aware of this special case and transform annotation strings of the form*tuple[...] intotyping.Unpack[tuple[...]] before evaluation, similar to whattyping.get_type_hints does.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard 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