Skip to content

Commit

Permalink
Allow return insertion without type hint (#11)
Browse files Browse the repository at this point in the history
* allow return insertion without typehint

* readme
  • Loading branch information
douglasdavis authored Jan 6, 2022
1 parent 2d280dd commit 385fc0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ RET numpydoc</kbd>
If <code>t</code> (the default) a Raises bock will be added to the
docstring if exceptions are detected in the function body.
</dd>
<dt>numpydoc-insert-return-without-typehint</dt>
<dd>
If <code>t</code> a Returns block will be inserted in the absence of
a return type hint.
</dd>
<dt>numpydoc-template-short</dt>
<dd>
Template text that will be used as the short description if
Expand Down
13 changes: 11 additions & 2 deletions numpydoc.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 385fc0b

Please sign in to comment.