Skip to content

Commit 6aee498

Browse files
committed
Apply suggestions
1 parent f77df2a commit 6aee498

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/sage/misc/sageinspect.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,12 +1329,8 @@ def sage_getfile(obj):
13291329
return sage_getfile(obj.func)
13301330
return sage_getfile(obj.__class__) # inspect.getabsfile(obj.__class__)
13311331
else:
1332-
try:
1333-
objinit = obj.__init__
1334-
except AttributeError:
1335-
pass
1336-
else:
1337-
pos = _extract_embedded_position(_sage_getdoc_unformatted(objinit))
1332+
if hasattr(obj, '__init__'):
1333+
pos = _extract_embedded_position(_sage_getdoc_unformatted(obj.__init__))
13381334
if pos is not None:
13391335
(_, filename, _) = pos
13401336
return filename
@@ -1347,6 +1343,7 @@ def sage_getfile(obj):
13471343
for suffix in import_machinery.EXTENSION_SUFFIXES:
13481344
if sourcefile.endswith(suffix):
13491345
# TODO: the following is incorrect in meson editable install
1346+
# because the build is out-of-tree,
13501347
# but as long as either the class or its __init__ method has a
13511348
# docstring, _sage_getdoc_unformatted should return correct result
13521349
# see https://github.com/mesonbuild/meson-python/issues/723
@@ -2370,12 +2367,8 @@ class Element:
23702367
try:
23712368
return inspect.getsourcelines(obj)
23722369
except (OSError, TypeError) as err:
2373-
try:
2374-
objinit = obj.__init__
2375-
except AttributeError:
2376-
pass
2377-
else:
2378-
d = _sage_getdoc_unformatted(objinit)
2370+
if hasattr(obj, '__init__'):
2371+
d = _sage_getdoc_unformatted(obj.__init__)
23792372
pos = _extract_embedded_position(d)
23802373
if pos is None:
23812374
if inspect.isclass(obj):

0 commit comments

Comments
 (0)