From 385fc0bdd648d5f8bffabc073662577c8941c86d Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Thu, 6 Jan 2022 11:03:44 -0600 Subject: [PATCH] Allow return insertion without type hint (#11) * allow return insertion without typehint * readme --- README.md | 5 +++++ numpydoc.el | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e231ec..cb45b97 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,11 @@ RET numpydoc If t (the default) a Raises bock will be added to the docstring if exceptions are detected in the function body. +
numpydoc-insert-return-without-typehint
+
+ If t a Returns block will be inserted in the absence of + a return type hint. +
numpydoc-template-short
Template text that will be used as the short description if diff --git a/numpydoc.el b/numpydoc.el index 071cfda..1ca1068 100644 --- a/numpydoc.el +++ b/numpydoc.el @@ -96,6 +96,11 @@ body has raise statements." :group 'numpydoc :type 'boolean) +(defcustom numpydoc-insert-return-without-typehint nil + "Flag to control inserting a Return block if a type hint is absent." + :group 'numpydoc + :type 'boolean) + (defcustom numpydoc-template-short "FIXME: Short description." "Template text for the short description in a docstring." :group 'numpydoc @@ -434,12 +439,16 @@ This function assumes the cursor to be in the function body." "Insert FNRET (return) description (if exists) at INDENT level." (let ((tmpr (cond ((numpydoc--yas-p) numpydoc--yas-replace-pat) (t numpydoc-template-arg-desc)))) - (when (and fnret (not (string= fnret "None"))) + (when (or numpydoc-insert-return-without-typehint + (and fnret (not (string= fnret "None")))) (insert "\n") (numpydoc--insert indent "Returns\n" "-------\n" - fnret) + (cond (fnret fnret) + ((numpydoc--prompt-p) (read-string "Return type: ")) + ((numpydoc--yas-p) numpydoc--yas-replace-pat) + (t numpydoc-template-type-desc))) (insert "\n") (numpydoc--insert indent (concat (make-string 4 ?\s)