fix(python) Do not duplicate "Throw" annotations (#142)

* Fixed Python docstring duplicate throw parsing error
* ref(python): remove unecessary recursive
* Stylua

---------

Co-authored-by: danymat <d.danymat@gmail.com>
This commit is contained in:
Colin Kennedy
2023-05-31 03:50:53 -07:00
committed by GitHub
parent de603d2f83
commit e449d5b7ff

View File

@@ -15,7 +15,6 @@ local parent = {
return { return {
-- Search for these nodes -- Search for these nodes
parent = parent, parent = parent,
-- Traverse down these nodes and extract the information as necessary -- Traverse down these nodes and extract the information as necessary
data = { data = {
func = { func = {
@@ -84,10 +83,16 @@ return {
subtree = { subtree = {
{ {
retrieve = "first", retrieve = "first",
node_type = "identifier", node_type = "call",
recursive = true, recursive = true,
extract = true, subtree = {
as = i.Throw, {
retrieve = "first",
node_type = "identifier",
extract = true,
as = i.Throw,
}
}
}, },
}, },
}, },
@@ -107,7 +112,7 @@ return {
for _, n in pairs(nodes[i.Tparam]) do for _, n in pairs(nodes[i.Tparam]) do
local type_subtree = { local type_subtree = {
{ retrieve = "all", node_type = "identifier", extract = true, as = i.Parameter }, { retrieve = "all", node_type = "identifier", extract = true, as = i.Parameter },
{ retrieve = "all", node_type = "type", extract = true, as = i.Type }, { retrieve = "all", node_type = "type", extract = true, as = i.Type },
} }
local typed_parameters = nodes_utils:matching_nodes_from(n, type_subtree) local typed_parameters = nodes_utils:matching_nodes_from(n, type_subtree)
typed_parameters = extractors:extract_from_matched(typed_parameters) typed_parameters = extractors:extract_from_matched(typed_parameters)
@@ -146,21 +151,21 @@ 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.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
@@ -258,12 +263,10 @@ return {
}, },
}, },
}, },
-- Use default granulator and generator -- Use default granulator and generator
locator = nil, locator = nil,
granulator = nil, granulator = nil,
generator = nil, generator = nil,
template = template template = template
:config({ :config({
append = { position = "after", child_name = "comment", fallback = "block", disabled = { "file" } }, append = { position = "after", child_name = "comment", fallback = "block", disabled = { "file" } },