Make sure that getargspec raises on built-in types

This commit is contained in:
Nathaniel J. Smith 2017-02-24 06:07:36 -08:00
parent 678eff821f
commit a3b80bc87a
2 changed files with 14 additions and 0 deletions

View File

@ -40,6 +40,15 @@ if PY3:
def getargspec(func):
"""Like inspect.getfullargspec but supports bound methods, and wrapped
methods."""
# On 3.5+, signature(int) or similar raises ValueError. On 3.4, it
# succeeds with a bogus signature. We want a TypeError uniformly, to
# match historical behavior.
if (isinstance(func, type)
and is_builtin_class_method(func, "__new__")
and is_builtin_class_method(func, "__init__")):
raise TypeError(
"can't compute signature for built-in type {}".format(func))
sig = inspect.signature(func)
args = []

View File

@ -13,10 +13,15 @@ from unittest import TestCase
from six import PY3
import functools
from textwrap import dedent
import pytest
from sphinx.util import inspect
class TestGetArgSpec(TestCase):
def test_getargspec_builtin_type(self):
with pytest.raises(TypeError):
inspect.getargspec(int)
def test_getargspec_partial(self):
def fun(a, b, c=1, d=2):
pass