Skip to content

Commit fc69881

Browse files
committed
Fix missing file error with sage_getdoc
1 parent 9f90540 commit fc69881

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/sage/misc/sageinspect.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,8 @@ def sage_getdoc(obj, obj_name='', embedded=False):
21562156
The optional boolean argument ``embedded`` controls the
21572157
string formatting. It is False by default.
21582158
2159+
Return ``None`` if the documentation string is invalid or missing.
2160+
21592161
INPUT:
21602162
21612163
- ``obj`` -- a function, module, etc.: something with a docstring
@@ -2166,7 +2168,8 @@ def sage_getdoc(obj, obj_name='', embedded=False):
21662168
sage: sage_getdoc(identity_matrix)[87:124] # needs sage.modules
21672169
'...the n x n identity matrix...'
21682170
sage: def f(a, b, c, d=1): return a+b+c+d
2169-
...
2171+
sage: sage_getdoc(f) is None
2172+
True
21702173
sage: import functools
21712174
sage: f1 = functools.partial(f, 1,c=2)
21722175
sage: f.__doc__ = "original documentation"
@@ -2175,13 +2178,25 @@ def sage_getdoc(obj, obj_name='', embedded=False):
21752178
'original documentation\n'
21762179
sage: sage_getdoc(f1)
21772180
'specialised documentation\n'
2181+
2182+
TESTS::
2183+
2184+
sage: class C:
2185+
....: '''
2186+
....: docs
2187+
....: '''
2188+
sage: sage_getdoc(C)
2189+
' docs\n'
21782190
"""
21792191
import sage.misc.sagedoc
21802192
if obj is None:
21812193
return ''
21822194
r = sage_getdoc_original(obj)
21832195
s = sage.misc.sagedoc.format(r, embedded=embedded)
2184-
f = sage_getfile(obj)
2196+
try:
2197+
f = sage_getfile(obj)
2198+
except OSError:
2199+
f = None
21852200
if f and os.path.exists(f):
21862201
from sage.doctest.control import skipfile
21872202
skip = skipfile(f)

0 commit comments

Comments
 (0)