@@ -256,35 +256,38 @@ This function assumes the cursor to be in the function body."
256
256
(defun numpydoc--parse-def (buffer-substr )
257
257
" Parse the BUFFER-SUBSTR; return instance of numpydoc--def."
258
258
(save-excursion
259
- (let* ((fnsig buffer-substr)
260
- ; ; trimmed string of the function signature
261
- (trimmed (s-collapse-whitespace fnsig))
262
- ; ; split into parts (args and return type)
263
- (parts (s-split " ->" trimmed))
264
- ; ; raw return
265
- (rawret (if (nth 1 parts)
266
- (s-trim (nth 1 parts))
267
- nil ))
268
- ; ; save return type as a string (or nil)
269
- (rtype (when rawret
270
- (substring rawret 0 (1- (length rawret)))))
271
- ; ; raw signature without return type as a string
272
- (rawsig (cond (rtype (substring (s-trim (car parts)) 0 -1 ))
273
- (t (substring (s-trim (car parts)) 0 -2 ))))
274
- ; ; function args as strings
275
- (rawargs (-map #'s-trim
276
- (numpydoc--split-args
277
- (substring rawsig
278
- (1+ (string-match-p (regexp-quote " (" )
279
- rawsig))))))
280
- ; ; function args as a list of structures (remove some special cases)
281
- (args (-remove (lambda (x )
282
- (-contains-p numpydoc-ignored-params
283
- (numpydoc--arg-name x)))
284
- (-map #'numpydoc--arg-str-to-struct rawargs)))
285
- ; ; look for exceptions in the function body
286
- (exceptions (numpydoc--find-exceptions)))
287
- (make-numpydoc--def :args args :rtype rtype :raises exceptions))))
259
+ (condition-case nil
260
+ (progn
261
+ (let* ((fnsig buffer-substr)
262
+ ; ; trimmed string of the function signature
263
+ (trimmed (s-collapse-whitespace fnsig))
264
+ ; ; split into parts (args and return type)
265
+ (parts (s-split " ->" trimmed))
266
+ ; ; raw return
267
+ (rawret (if (nth 1 parts)
268
+ (s-trim (nth 1 parts))
269
+ nil ))
270
+ ; ; save return type as a string (or nil)
271
+ (rtype (when rawret
272
+ (substring rawret 0 (1- (length rawret)))))
273
+ ; ; raw signature without return type as a string
274
+ (rawsig (cond (rtype (substring (s-trim (car parts)) 0 -1 ))
275
+ (t (substring (s-trim (car parts)) 0 -2 ))))
276
+ ; ; function args as strings
277
+ (rawargs (-map #'s-trim
278
+ (numpydoc--split-args
279
+ (substring rawsig
280
+ (1+ (string-match-p (regexp-quote " (" )
281
+ rawsig))))))
282
+ ; ; function args as a list of structures (remove some special cases)
283
+ (args (-remove (lambda (x )
284
+ (-contains-p numpydoc-ignored-params
285
+ (numpydoc--arg-name x)))
286
+ (-map #'numpydoc--arg-str-to-struct rawargs)))
287
+ ; ; look for exceptions in the function body
288
+ (exceptions (numpydoc--find-exceptions)))
289
+ (make-numpydoc--def :args args :rtype rtype :raises exceptions)))
290
+ (error " Failed to parse function signature (bad Python syntax). " ))))
288
291
289
292
(defun numpydoc--has-existing-docstring-p ()
290
293
" Check for an existing docstring.
0 commit comments