title: How can I use Python to refactor nested function calls into lines of code?
body: <p>I'm looking for some way to do this with Python itself, not using an IDE.</p>
  
  <p>Example:</p>
  
  <pre><code>def upper(string):
      return string.upper()
  
  def reverse_string(string):
      return string[::-1]
  
  string = 'abc'
  reverse_upper = reverse_string(upper(string))
  </code></pre>
  
  <p>Converts to:</p>
  
  <pre><code>string = 'abc'
  reverse_upper = string.upper()[::-1]
  </code></pre>
  
  <p>I'm considering making a solution that works recursively with <a href="https://docs.python.org/3/library/inspect.html#inspect.getsourcelines" rel="nofollow noreferrer">inspect.getsourcelines</a>. Is there any other function or library that will get me further along?</p>