Skip to content

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

@neutrinoceros

Description

@neutrinoceros

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy