@@ -101,9 +101,8 @@ def _get_source_from_interpreter_function(raw_func):
101
101
current_interpreter_history = readline .get_current_history_length ()
102
102
103
103
try :
104
- search_pattern = re .compile (r"^(\s*def\s)" )
104
+ search_pattern = re .compile (r"^(\s*def\s*" + raw_func . __name__ + r"\s*\( )" )
105
105
decorator_pattern = re .compile (r"^(\s*@)" )
106
- func_name = raw_func .__name__
107
106
code_object = raw_func .__func__ if inspect .ismethod (raw_func ) else raw_func .__code__
108
107
except Exception :
109
108
raise OSError ("Could not get source code for interpreter-defined function." )
@@ -120,21 +119,23 @@ def _get_source_from_interpreter_function(raw_func):
120
119
121
120
# if its a def name_of_function(...
122
121
if search_pattern .match (line ):
123
- # go through to get decorators
124
- if func_name in line :
125
- # reassemble function
126
- for i in range (starting_index_of_function , current_interpreter_history + 1 ):
127
- reassembled_function += f"{ readline .get_history_item (i )} \n "
128
-
129
- for line_number_with_decorator in range (starting_index_of_function - 1 , - 1 , - 1 ):
130
- if decorator_pattern .match (readline .get_history_item (line_number_with_decorator )):
131
- reassembled_function = (
132
- f"{ readline .get_history_item (line_number_with_decorator )} \n " + reassembled_function
133
- )
134
- else :
135
- break
136
- break
122
+ # reassemble function
123
+ for i in range (starting_index_of_function , current_interpreter_history + 1 ):
124
+ reassembled_function += f"{ readline .get_history_item (i )} \n "
125
+
126
+ for line_number_with_decorator in range (starting_index_of_function - 1 , - 1 , - 1 ):
127
+ if decorator_pattern .match (readline .get_history_item (line_number_with_decorator )):
128
+ reassembled_function = (
129
+ f"{ readline .get_history_item (line_number_with_decorator )} \n " + reassembled_function
130
+ )
131
+ else :
132
+ break
133
+ break
137
134
starting_index_of_function -= 1
135
+
136
+ if reassembled_function == "" :
137
+ raise OSError ("Could not find function definition for interpreter-defined function." )
138
+
138
139
return reassembled_function
139
140
140
141
0 commit comments