LineaLabs / lineapy

Move fast from data science prototype to pipeline. Capture, analyze, and transform messy notebooks into data pipelines with just two lines of code.
https://lineapy.org
Apache License 2.0
662 stars 58 forks source link

Lin 586 slicing error with multi line parenthesis block #785

Closed mingjerli closed 1 year ago

mingjerli commented 1 year ago

Description

Multi-line statements are causing a slicing error. A temporary solution is wrapping each statement into online, so our code slice mechanism should work. Especially when we have meaningless parentheses.

Consider following code

x = 1
y = 2
a = (
    x+y
)
arta = lineapy.save(a,'a')
arta.get_code()

currently, we will see error because we only slice out

x = 1
y = 2
    x+y

and the indentation is not correct.

This PR is modifying the user code as

x = 1
y = 2
a = x+y
arta = lineapy.save(a,'a')
arta.get_code()

before it goes to the tracer; so we can get the following sliced code

x = 1
y = 2
a = x+y

This will not affect end code generation result, since it is running through black before return.

Some edge cases to consider

Fixes # (issue)

How Has This Been Tested?

Pass all existing tests

mingjerli commented 1 year ago

Choose alternative solution https://github.com/LineaLabs/lineapy/pull/787