title: Automatically refactor python lambdas to named functions
body: <p>I am working on the <a href="https://github.com/purescript-python" rel="noreferrer">purescript-python</a> project and there are several core libraries that make extensive use of lambdas. Because of the way the code is compiled, the location of the lambdas winds up getting obscured, which results in bizarre console messages whenever an error occurs.</p>
  <p>I would like to refactor these libraries to use lambdas as little as possible. So, for example, if there is something like:</p>
  <pre class="lang-py prettyprint-override"><code>def foo(a):
    return lambda b: lambda c: lambda d: lambda e: a + b + c + d + e
  </code></pre>
  <p>it would be nice to generate</p>
  <pre class="lang-py prettyprint-override"><code>def foo(a):
    def _foo_internal_anon_1(b):
      def _foo_internal_anon_2(c):
          def _foo_internal_anon_3(d):
            def _foo_internal_anon_4(e):
              return a + b + c + d + e
            return _foo_internal_anon_4
          return _foo_internal_anon_3
      return _foo_internal_anon_2
    return _foo_internal_anon_1
  </code></pre>
  <p>Is there a way to do this, ie with <code>pylint</code> or a vscode or pycharm plugin, or does this have to be done by hand?</p>