obj = obj.fget
if inspect.isfunction(obj) and getattr(obj, '__doc__', None):
# We don't use `docstring` var here, because `obj` can be changed.
- obj = inspect.unwrap(obj).__code__
+ obj = inspect.unwrap(obj)
+ try:
+ obj = obj.__code__
+ except AttributeError:
+ # Functions implemented in C don't necessarily
+ # have a __code__ attribute.
+ # If there's no code, there's no lineno
+ return None
if inspect.istraceback(obj): obj = obj.tb_frame
if inspect.isframe(obj): obj = obj.f_code
if inspect.iscode(obj):
'one other test'
"""
+@doctest_skip_if(support.check_impl_detail(cpython=False))
+def test_wrapped_c_func():
+ """
+ # https://github.com/python/cpython/issues/117692
+ >>> import binascii
+ >>> from test.test_doctest.decorator_mod import decorator
+
+ >>> c_func_wrapped = decorator(binascii.b2a_hex)
+ >>> tests = doctest.DocTestFinder(exclude_empty=False).find(c_func_wrapped)
+ >>> for test in tests:
+ ... print(test.lineno, test.name)
+ None b2a_hex
+ """
+
def test_unittest_reportflags():
"""Default unittest reporting flags can be set to control reporting