Removed return if body is not found (python)

This commit is contained in:
Daniel Mathiot
2021-08-23 20:03:14 +02:00
parent db3a136f7f
commit 790c98edf1

View File

@@ -10,21 +10,28 @@ return {
["0"] = { ["0"] = {
extract = function (node) extract = function (node)
local results = { local results = {
parameters = {} parameters = {},
return_statement = {}
} }
local params = neogen.utilities.nodes:matching_child_nodes(node, "parameters")[1] local params = neogen.utilities.nodes:matching_child_nodes(node, "parameters")[1]
if #params == 0 then
results.parameters = nil
end
local found_nodes local found_nodes
if #params ~= 0 then
-- Find regular parameters -- Find regular parameters
local regular_params = neogen.utilities.extractors:extract_children_text("identifier")(params) local regular_params = neogen.utilities.extractors:extract_children_text("identifier")(params)
if #regular_params == 0 then if #regular_params == 0 then
regular_params = nil regular_params = nil
end end
for _, _params in pairs(regular_params) do
table.insert(results.parameters, _params)
end
results.parameters = regular_params results.parameters = regular_params
-- Find regular optional parameters -- Find regular optional parameters
@@ -48,18 +55,18 @@ return {
table.insert(results.parameters, _params) table.insert(results.parameters, _params)
end end
end
local body = neogen.utilities.nodes:matching_child_nodes(node, "block")[1] local body = neogen.utilities.nodes:matching_child_nodes(node, "block")[1]
if body == nil then if body ~= nil then
return
end
local return_statement = neogen.utilities.nodes:matching_child_nodes(body, "return_statement") local return_statement = neogen.utilities.nodes:matching_child_nodes(body, "return_statement")
if #return_statement == 0 then if #return_statement == 0 then
return_statement = nil return_statement = nil
end end
results.return_statement = return_statement results.return_statement = return_statement
end
return results return results
end end
@@ -108,7 +115,7 @@ return {
generator = nil, generator = nil,
template = { template = {
annotation_convention = "google_docstrings", -- required: Which annotation convention to use (default_generator) annotation_convention = "numpydoc", -- required: Which annotation convention to use (default_generator)
append = { position = "after", child_name = "block" }, -- optional: where to append the text (default_generator) append = { position = "after", child_name = "block" }, -- optional: where to append the text (default_generator)
use_default_comment = false, -- If you want to prefix the template with the default comment for the language, e.g for python: # (default_generator) use_default_comment = false, -- If you want to prefix the template with the default comment for the language, e.g for python: # (default_generator)
google_docstrings = { google_docstrings = {