ploomber / soorgeon

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

Failure when function uses global variable #13

Closed edublancas closed 2 years ago

edublancas commented 2 years ago

GIven the snippet:

def p():
    print(x)

x = 1

p()

When parsing def p(), we'll find the x in the body and assign it as an input, since at that point, we haven't seen that the user is declaring an x.

There are a couple of options here, one could be to put inputs inside function definitions in stage mode and determine whether they're inputs or not depending on whether the variable exists when they're first called.

Another alternative is to raise an error, perform the refactoring by adding x to the signature, modify the instances where the function is called and then starting again. See #12

I think the latter is a better option.

edublancas commented 2 years ago

as a solution to this, we now tell users to refactor the fns: https://github.com/ploomber/soorgeon/blob/main/doc/fn-global.md