mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make sure that getargspec raises on built-in types
This commit is contained in:
parent
678eff821f
commit
a3b80bc87a
@ -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 = []
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user