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 — 3.13.0b3 regression: inspect.signature + unittest.mock · Issue #121257 · python/cpython

3.13.0b3 regression: inspect.signature + unittest.mock #121257

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
3.13.0b3 regression: inspect.signature + unittest.mock#121257
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@neutrinoceros
neutrinoceros
opened on Jul 2, 2024
Issue body actions

Bug report

Bug description:

MRE:

import inspect
import functools
from unittest import TestCase
import unittest.mock as mk

class TestIsinstance(TestCase):
    def test_mk(self):
        def foo(): pass
        with mk.patch.object(functools, "partial", autospec=True):
            inspect.signature(foo)

fails with

E
======================================================================
ERROR: test_mk (test.TestIsinstance.test_mk)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/private/tmp/reprod/test.py", line 10, in test_mk
    inspect.signature(foo)
    ~~~~~~~~~~~~~~~~~^^^^^
  File "/Users/clm/.pyenv/versions/3.13.0b3/lib/python3.13/inspect.py", line 3333, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                   globals=globals, locals=locals, eval_str=eval_str)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clm/.pyenv/versions/3.13.0b3/lib/python3.13/inspect.py", line 3059, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
                                    follow_wrapper_chains=follow_wrapped,
                                    globals=globals, locals=locals, eval_str=eval_str)
  File "/Users/clm/.pyenv/versions/3.13.0b3/lib/python3.13/inspect.py", line 2559, in _signature_from_callable
    if isinstance(obj, functools.partial):
       ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)

reproduces locally and in CI: example logs

this test case is adapted from a real life application in astropy's test suite, which has been stable since at least Python 3.8

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13

Operating systems tested on:

Linux, macOS, Windows

Activity

  1. neutrinoceros
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 2, 2024
  2. neutrinoceros
    changed the title [-]3.13.0b3 regression: [/-] [+]3.13.0b3 regression: inspect.signature + unittest.mock[/+] on Jul 2, 2024
  3. picnixz commented on Jul 2, 2024

    @picnixz
    picnixz
    on Jul 2, 2024
    Member
    More actions

    Could it be because of #121092? (especially: https://github.com/python/cpython/pull/121092/files#diff-b89cd06e4637abacb73f2500301ff979a67ad7ecbfa7cf151c7243715898d7eaL2570-L2573)

  4. neutrinoceros commented on Jul 2, 2024

    @neutrinoceros
    neutrinoceros
    on Jul 2, 2024
    ContributorAuthor
    More actions

    Thank you ! It's definitely related: the test pass if I revert just the bit you pointed to.

  5. picnixz commented on Jul 2, 2024

    @picnixz
    picnixz
    on Jul 2, 2024
    Member
    More actions

    cc @serhiy-storchaka

  6. Eclips4
    added
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    on Jul 2, 2024
  7. serhiy-storchaka commented on Jul 2, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 2, 2024
    Member
    More actions

    It is not safe to patch functools.partial which is used in the inspect module and then use the inspect module.

    Add the following code in your example and you will see that it was broken before #121092.

                inspect.signature(self.test_mk)
                def bar(x: int) -> None: pass
                inspect.get_annotations(bar, eval_str=True)
  8. neutrinoceros commented on Jul 2, 2024

    @neutrinoceros
    neutrinoceros
    on Jul 2, 2024
    ContributorAuthor
    More actions

    Thanks for pointing this out !
    I was able to resolve this on our side by avoiding mocking altogether at astropy/astropy#16659
    Feel free to close this issue.

  9. serhiy-storchaka
    closed this as not plannedon Jul 2, 2024
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.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestype-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.