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

Autospeccing withunittest.mock is less robust with PEP 649 #145754

Labels
3.14bugs and security fixes3.15new features, bugs and security fixestopic-typingtype-bugAn unexpected behavior, bug, or error
@Daverball

Description

@Daverball

Bug report

Bug description:

fromtypingimportTYPE_CHECKINGfromunittest.mockimportcreate_autospecifTYPE_CHECKING:fromfooimportFoodefbar(x:Foo)->None:passcreate_autospec(bar)

This will result inNameError: name 'Foo' is not defined because_get_signature_object inunittest.mock callsinspect.signature without explicitly passingannotation_format, so it defaults toFormat.VALUE.

Sincecreate_autospec really shouldn't care whether or not the annotations can be evaluated at runtime on the given object, I would suggest switching over toFormat.FORWARDREF orFormat.STRING, so autospeccing continues to work in Python 3.14+ for people that used to rely onfrom __future__ import annotations and now want to switch to PEP 649 semantics, without needing to change their code.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixestopic-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-2026 Movatter.jp