Jungroth
Jungroth

Reputation: 422

How can I use Python to refactor nested function calls into lines of code?

I'm looking for some way to do this with Python itself, not using an IDE.

Example:

def upper(string):
    return string.upper()

def reverse_string(string):
    return string[::-1]

string = 'abc'
reverse_upper = reverse_string(upper(string))

Converts to:

string = 'abc'
reverse_upper = string.upper()[::-1]

I'm considering making a solution that works recursively with inspect.getsourcelines. Is there any other function or library that will get me further along?

Upvotes: 2

Views: 117

Answers (1)

Jungroth
Jungroth

Reputation: 422

This comment from @kaya3 got me here.

There are two repos that do this that I can use as starting points: inliner and atinline. Neither are maintained, but I can use them for reference.

Upvotes: 2

Related Questions