fix(python): Check for assignment to non-attributes in class (#107)

This commit is contained in:
root
2022-11-03 00:07:40 +01:00
parent c9ee823ec2
commit da04629ffa

View File

@@ -224,13 +224,21 @@ return {
return {} return {}
end end
-- Deliberately check inside the init function for assignments to "self"
results[i.ClassAttribute] = {} results[i.ClassAttribute] = {}
for _, assignment in pairs(nodes["assignment"]) do for _, assignment in pairs(nodes["assignment"]) do
local left_side = assignment:field("left")[1] -- Getting left side in assignment
local left_attribute = left_side:field("attribute")[1] local left = assignment:field("left")
left_attribute = helpers.get_node_text(left_attribute)[1]
if left_attribute and not vim.startswith(left_attribute, "_") then -- Checking if left side is an "attribute", which means assigning to an attribute to the function
table.insert(results[i.ClassAttribute], left_attribute) if not vim.tbl_isempty(left) and not vim.tbl_isempty(left[1]:field("attribute")) then
--Adding it to the list
local left_attribute = assignment:field("left")[1]:field("attribute")[1]
left_attribute = helpers.get_node_text(left_attribute)[1]
if not vim.startswith(left_attribute, "_") then
table.insert(results[i.ClassAttribute], left_attribute)
end
end end
end end
if vim.tbl_isempty(results[i.ClassAttribute]) then if vim.tbl_isempty(results[i.ClassAttribute]) then