ploomber / soorgeon

Convert monolithic Jupyter notebooks 📙 into maintainable Ploomber pipelines. 📊
https://ploomber.io
Apache License 2.0
78 stars 20 forks source link

Support using global variables inside a function's body #89

Closed rrhg closed 1 month ago

rrhg commented 1 year ago

Previously, we did not support using global variables inside a function's body:

        x = 1
        def sum(y):
            return x + y
        sum(y)

The above would break since sum is using a variable that's defined outside the function's body. If a user tried to refactor a notebook with code like this using Soorgeon refactor, they would get an error message asking them to change the code to:

        x = 1
        def sum(y, x):
            return x + y
        sum(y, x)

This PR automate this process and modify the user's source code on their behalf so they don't have to do it manually.

https://github.com/ploomber/soorgeon/issues/65

Closes #65

Checklist before requesting a review

rrhg commented 1 year ago

Need advice on these issues:

class methods:

Nested function definitions:

Would throw an error: undefined name nested. Apparently is a known limitation of pyflakes. In export.py, if we comment out the line pyflakes.check_notebook(self._nb), we don't get that error, but the code won't be checked by pyflakes.

Integration tests are failing: