Skip to content

Commit c0bdca0

Browse files
committed
Fix get_source_of_current_name to raise exceptions instead of returning None
1 parent b80b400 commit c0bdca0

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

bpython/repl.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -591,19 +591,16 @@ def get_source_of_current_name(self):
591591
"""Return the source code of the object which is bound to the
592592
current name in the current input line. Return `None` if the
593593
source cannot be found."""
594-
try:
595-
obj = self.current_func
594+
obj = self.current_func
595+
if obj is None:
596+
line = self.current_line
597+
if line == "":
598+
raise ValueError("Cannot get source of an empty string")
599+
if inspection.is_eval_safe_name(line):
600+
obj = self.get_object(line)
596601
if obj is None:
597-
line = self.current_line
598-
if inspection.is_eval_safe_name(line):
599-
obj = self.get_object(line)
600-
if obj is None:
601-
return None
602-
source = inspect.getsource(obj)
603-
except (AttributeError, IOError, NameError, TypeError):
604-
return None
605-
else:
606-
return source
602+
raise NameError("%s is not defined" % line)
603+
return inspect.getsource(obj) #throws an exception that we'll catch
607604

608605
def set_docstring(self):
609606
self.docstring = None

0 commit comments

Comments
 (0)