inspect.getdoc return different value with -OO
In CPython, inspect.getdoc
is documented to retrieve the documentation string from the inheritance hierarchy when not provided. This is the case for things even if they have an existing docstring, when -OO
is passed.
Example script:
import inspect
class Foo:
def __init__(self):
"""Foo init"""
print(inspect.getdoc(Foo.__init__))
On CPython:
$ python --version
Python 3.7.6
$ python foo.py
Foo init
$ python -OO foo.py
Initialize self. See help(type(self)) for accurate signature.
On PyPy though, it returns None
:
$ python --version
Python 3.7.10 (76f47b474df0, Aug 11 2021, 11:41:05)
[PyPy 7.3.4 with GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
$ python foo.py
Foo init
$ python -OO foo.py
None