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-655: Add support for byte literals #816

Closed andycui97 closed 1 year ago

andycui97 commented 1 year ago

Description

Add support for byte literals

Fixes LIN-655

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

a = b"Hello World!"
art_a = lineapy.save(a, "a")
art_a.get_code()
art_a.get_value()

Added test cases for Literal Node under tests/unit/db/test_literal_node.py.

lionsardesai commented 1 year ago

actually i take that back. the fact that the test fails in py3.7 tells me that bytes behaves differently for that version. lets have a quick sync on this before merging

lionsardesai commented 1 year ago

ok a quick check gives me this: in python 3.7:

>>> import ast
>>> from astpretty import pprint
>>> pprint(ast.parse("b'10'"))
Module(
    body=[
        Expr(
            lineno=1,
            col_offset=0,
            value=Bytes(lineno=1, col_offset=0, s=b'10'),
        ),
    ],
)
>>> 

and in 3.9:

>>> import ast
>>> from astpretty import pprint
>>> pprint(ast.parse("b'10'"))
Module(
    body=[
        Expr(
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=5,
            value=Constant(lineno=1, col_offset=0, end_lineno=1, end_col_offset=5, value=b'10', kind=None),
        ),
    ],
    type_ignores=[],
)

so we need to add a visit_Bytes that is only triggered in python 3.7