Skip to content

Commit 21dd822

Browse files
committed
Change to AssertionError and handle issue upstream
1 parent d8d3288 commit 21dd822

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/sage/misc/sageinspect.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,11 +1140,10 @@ def _sage_getargspec_cython(source):
11401140
defaults=('a string', {(1, 2, 3): True}),
11411141
kwonlyargs=[], kwonlydefaults=None, annotations={})
11421142
"""
1143-
if not isinstance(source, str):
1144-
# the caller ought to ensure this, but if it forgets (e.g. passing None),
1145-
# we raise the correct exception type to avoid confusing error message
1146-
# and possible further hard-to-debug errors, see :issue:`39735`
1147-
raise TypeError
1143+
assert isinstance(source, str)
1144+
# the caller ought to ensure this, but if it forgets (e.g. passing None),
1145+
# we avoid raising AttributeError to avoid confusing error message
1146+
# and possible further hard-to-debug errors, see :issue:`39735`
11481147
defpos = source.find('def ')
11491148
assert defpos > -1, "The given source does not contain 'def'"
11501149
s = source[defpos:].strip()
@@ -1682,12 +1681,15 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return
16821681
except TypeError: # arg is not a code object
16831682
# The above "hopefully" was wishful thinking:
16841683
try:
1685-
return inspect.FullArgSpec(*_sage_getargspec_cython(sage_getsource(obj)))
1684+
source = sage_getsource(obj)
16861685
except TypeError: # This happens for Python builtins
1687-
# The best we can do is to return a generic argspec
1688-
args = []
1689-
varargs = 'args'
1690-
varkw = 'kwds'
1686+
source = None
1687+
if source is not None:
1688+
return inspect.FullArgSpec(*_sage_getargspec_cython(source))
1689+
# The best we can do is to return a generic argspec
1690+
args = []
1691+
varargs = 'args'
1692+
varkw = 'kwds'
16911693
try:
16921694
defaults = func_obj.__defaults__
16931695
except AttributeError:

0 commit comments

Comments
 (0)