fix(python): Bare-returns are filtered from docstring output (#145)
* Python docstrings - bare-returns are filtered from docstring output * Stylua * doc: Version --------- Co-authored-by: danymat <d.danymat@gmail.com>
This commit is contained in:
@@ -12,6 +12,31 @@ local parent = {
|
|||||||
type = { "expression_statement" },
|
type = { "expression_statement" },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- Modify `nodes` if the found return(s) are **all** bare-returns.
|
||||||
|
---
|
||||||
|
--- A bare-return is used to return early from a function and aren't meant to be
|
||||||
|
--- assigned so they should not be included in docstring output.
|
||||||
|
---
|
||||||
|
--- If at least one return is not a bare-return then this function does nothing.
|
||||||
|
---
|
||||||
|
---@param nodes table
|
||||||
|
local validate_bare_returns = function(nodes)
|
||||||
|
local return_node = nodes[i.Return]
|
||||||
|
local has_data = false
|
||||||
|
|
||||||
|
for _, value in pairs(return_node) do
|
||||||
|
if value:child_count() > 1
|
||||||
|
then
|
||||||
|
has_data = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not has_data
|
||||||
|
then
|
||||||
|
nodes[i.Return] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
-- Search for these nodes
|
-- Search for these nodes
|
||||||
parent = parent,
|
parent = parent,
|
||||||
@@ -119,6 +144,11 @@ return {
|
|||||||
table.insert(temp[i.Tparam], typed_parameters)
|
table.insert(temp[i.Tparam], typed_parameters)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if nodes[i.Return] then
|
||||||
|
validate_bare_returns(nodes)
|
||||||
|
end
|
||||||
|
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
res[i.Tparam] = temp[i.Tparam]
|
res[i.Tparam] = temp[i.Tparam]
|
||||||
|
|
||||||
@@ -151,24 +181,24 @@ return {
|
|||||||
end
|
end
|
||||||
|
|
||||||
local results = helpers.copy({
|
local results = helpers.copy({
|
||||||
[i.HasParameter] = function(t)
|
[i.HasParameter] = function(t)
|
||||||
return (t[i.Parameter] or t[i.Tparam]) and { true }
|
return (t[i.Parameter] or t[i.Tparam]) and { true }
|
||||||
end,
|
end,
|
||||||
[i.HasReturn] = function(t)
|
[i.HasReturn] = function(t)
|
||||||
return (t[i.ReturnTypeHint] or t[i.Return]) and { true }
|
return (t[i.ReturnTypeHint] or t[i.Return]) and { true }
|
||||||
end,
|
end,
|
||||||
[i.HasThrow] = function(t)
|
[i.HasThrow] = function(t)
|
||||||
return t[i.Throw] and { true }
|
return t[i.Throw] and { true }
|
||||||
end,
|
end,
|
||||||
[i.Type] = true,
|
[i.Type] = true,
|
||||||
[i.Parameter] = true,
|
[i.Parameter] = true,
|
||||||
[i.Return] = true,
|
[i.Return] = true,
|
||||||
[i.ReturnTypeHint] = true,
|
[i.ReturnTypeHint] = true,
|
||||||
[i.ArbitraryArgs] = true,
|
[i.ArbitraryArgs] = true,
|
||||||
[i.Kwargs] = true,
|
[i.Kwargs] = true,
|
||||||
[i.Throw] = true,
|
[i.Throw] = true,
|
||||||
[i.Tparam] = true,
|
[i.Tparam] = true,
|
||||||
}, res) or {}
|
}, res) or {}
|
||||||
|
|
||||||
-- Removes generation for returns that are not typed
|
-- Removes generation for returns that are not typed
|
||||||
if results[i.ReturnTypeHint] then
|
if results[i.ReturnTypeHint] then
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ end
|
|||||||
--- with multiple annotation conventions.
|
--- with multiple annotation conventions.
|
||||||
---@tag neogen-changelog
|
---@tag neogen-changelog
|
||||||
---@toc_entry Changes in neogen plugin
|
---@toc_entry Changes in neogen plugin
|
||||||
neogen.version = "2.14.0"
|
neogen.version = "2.14.1"
|
||||||
--minidoc_afterlines_end
|
--minidoc_afterlines_end
|
||||||
|
|
||||||
return neogen
|
return neogen
|
||||||
|
|||||||
Reference in New Issue
Block a user