diff options
Diffstat (limited to 'sphinx/util/inspect.py')
-rw-r--r-- | sphinx/util/inspect.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 8cbf59bde..d2d5dd0a3 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +import re + # this imports the standard library inspect module without resorting to # relatively import this module inspect = __import__('inspect') @@ -18,6 +20,8 @@ from six.moves import builtins from sphinx.util import force_decode +memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>$)') + if PY3: from functools import partial @@ -123,14 +127,17 @@ def safe_getmembers(object, predicate=None, attr_getter=safe_getattr): return results -def safe_repr(object): +def object_description(object): """A repr() implementation that returns text safe to use in reST context.""" try: s = repr(object) except Exception: raise ValueError if isinstance(s, binary_type): - return force_decode(s, None).replace('\n', ' ') + s = force_decode(s, None) + # Strip non-deterministic memory addresses such as + # ``<__main__.A at 0x7f68cb685710>`` + s = memory_address_re.sub('', s) return s.replace('\n', ' ') |