GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Autospeccing with `unittest.mock` is less robust with PEP 649 · Issue #145754 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
#145756
Closed
Autospeccing with unittest.mock is less robust with PEP 649#145754
#145756
Copy link
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@Daverball
Daverball
opened on Mar 10, 2026
Issue body actions

Bug report

Bug description:

from typing import TYPE_CHECKING
from unittest.mock import create_autospec

if TYPE_CHECKING:
    from foo import Foo

def bar(x: Foo) -> None:
    pass

create_autospec(bar)

This will result in NameError: name 'Foo' is not defined because _get_signature_object in unittest.mock calls inspect.signature without explicitly passing annotation_format, so it defaults to Format.VALUE.

Since create_autospec really shouldn't care whether or not the annotations can be evaluated at runtime on the given object, I would suggest switching over to Format.FORWARDREF or Format.STRING, so autospeccing continues to work in Python 3.14+ for people that used to rely on from __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

  • gh-145754: Update signature retrieval in unittest.mock to use forwardref annotation format #145756
  • [3.14] gh-145754: Update signature retrieval in unittest.mock to use forwardref annotation format (GH-145756) #146191
Reacted by Matthieu Rigal

Activity

  1. Daverball
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 10, 2026
  2. mschoettle
    marked unittest.mock requests VALUE annotation format when calling inspect.signature #145755 as a duplicate of this issue on Mar 10, 2026
  3. johnslavik
    added
    topic-typing
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-typing
    on Mar 10, 2026
  4. JelleZijlstra
    added a commit that references this issue on Mar 20, 2026

    gh-145754: Update signature retrieval in unittest.mock to use forward…

    d357a7d
  5. JelleZijlstra
    closed this as completedin #145756on Mar 20, 2026
  6. miss-islington
    added a commit that references this issue on Mar 20, 2026

    pythongh-145754: Update signature retrieval in unittest.mock to use f…

    186b50d
  7. JelleZijlstra
    added a commit that references this issue on Mar 20, 2026

    [3.14] gh-145754: Update signature retrieval in unittest.mock to use …

    7ba9580
  8. CuriousLearner
    added a commit that references this issue on Mar 22, 2026

    Merge remote-tracking branch 'upstream/main' into fix-pythongh-138577

    2691ad9
  9. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-145754: Update signature retrieval in unittest.mock to use f…

    ec9558a
  10. akhmialeuski
    added a commit that references this issue on Oct 18, 2026

    refactor(tests): remove the leftovers of the in-memory adapter from t…

    d7002c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.