Skip to content

fix(python 106): various fixes #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lua/refactoring/code_generation/langs/python.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
local code_utils = require("refactoring.code_generation.utils")

---@param args string[]
---@param arg_types string[]
---@return string[]
local function build_args(args, arg_types)
local final_args = {}
local final_args = {} ---@type string[]
for i, arg in pairs(args) do
if arg_types[arg] ~= code_utils.default_func_param_type() then
final_args[i] = arg .. ": " .. arg_types[arg]
Expand All @@ -22,7 +25,6 @@ local function python_function(opts)
%sdef %s(%s):
%s


]],
opts.func_header,
opts.name,
Expand All @@ -44,7 +46,6 @@ local function python_function_return(opts)
%sdef %s(%s) -> %s:
%s


]],
opts.func_header,
opts.name,
Expand All @@ -56,15 +57,15 @@ end

local function python_class_function(opts)
local args = build_args(opts.args, opts.args_types)
args = vim.list_extend({ "self" }, args)
if opts.func_header == nil then
opts.func_header = ""
end
return string.format(
[[
%sdef %s(self, %s):
%sdef %s(%s):
%s


]],
opts.func_header,
opts.name,
Expand All @@ -75,6 +76,7 @@ end

local function python_class_function_return(opts)
local args = build_args(opts.args, opts.args_types)
args = vim.list_extend({ "self" }, args)
if opts.func_header == nil then
opts.func_header = ""
end
Expand All @@ -83,10 +85,9 @@ local function python_class_function_return(opts)
end
return string.format(
[[
%sdef %s(self, %s) -> %s:
%sdef %s(%s) -> %s:
%s


]],
opts.func_header,
opts.name,
Expand Down Expand Up @@ -176,4 +177,5 @@ local python = {
return string.format(opts.statement, opts.prefix, opts.var)
end,
}

return python
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Poggers:
def simple_function(self, a):
test = 1
# __AUTO_GENERATED_PRINTF_START__
print(f"Poggers#simple_function 1") # __AUTO_GENERATED_PRINTF_END__
print("Poggers#simple_function 1") # __AUTO_GENERATED_PRINTF_END__
test_other = 11
for x in range(test_other + test):
print(x, a)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def foo(self, a):
print(x, a)



def simple_function(self, a):
self.test = 1
self.test_other = 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def foo(self, a, test):
print(x, a)



def simple_function(self, a):
test = 3
self.test = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def foo(self, a, test) -> None:
return test_other



def simple_function(self, a):
test = 1
test_other = self.foo(a, test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def foo(self, a, test, test_other):
print(x, a)



def simple_function(self, a):
test = 1
test_other = 11
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
9
8
4
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ def foo_bar(a, b: int, c, d: int):
for x in range(test_other + test):
print(x, a, b, c, d)


def simple_function(a, b: int, c=1, d: int = 2):
foo_bar(a, b, c, d)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ def foo():
print("o hai")
print("o hai")


foo()
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
9
8
4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
def foo_bar(a, x):
print(x, a)


def simple_function(a):
test = 1
test_other = 11
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
9
8
4
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ def extracted_func() -> None:
b = 1
return a, b


def simple_function():
a, b = extracted_func()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
10
9
4
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ def foo_bar(a, b: int, c, d: int, test, test_other):
for x in range(test_other + test):
print(x, a, b, c, d)


def simple_function(a, b: int, c=1, d: int = 2):
test = 1
test_other = 11
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
14
13
4
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ def foo_bar(a, test, test_other):
print(x, a)



# This is a comment
# I use arch btw
# wow!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
16
15
4
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def extracted_fun():
dont_do_much += i



@my_decorator
@my_decorator
@my_decorator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
17
16
4
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def foo() -> None:
return bad_doc_ids, id



if __name__ == "main":
bad_doc_ids, id = foo()

Expand Down
Loading