Skip to content

LIN-161 - unit tests for node transformer. #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions lineapy/transformer/node_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,21 +569,11 @@ def visit_Subscript(self, node: ast.Subscript) -> CallNode:
args = [self.visit(node.value)]
index = node.slice
args.append(self.visit(index))
if isinstance(node.ctx, ast.Load):
return self.tracer.call(
self.tracer.lookup_node(GET_ITEM),
self.get_source(node),
*args,
)
elif isinstance(node.ctx, ast.Del):
raise NotImplementedError(
"Subscript with ctx=ast.Del() not supported."
)
else:
raise ValueError(
"Subscript with ctx=ast.Store() should have been handled by"
" visit_Assign."
)
return self.tracer.call(
self.tracer.lookup_node(GET_ITEM),
self.get_source(node),
*args,
)

def visit_Attribute(self, node: ast.Attribute) -> CallNode:

Expand Down
31 changes: 0 additions & 31 deletions lineapy/transformer/source_giver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@


class SourceGiver:
def __init__(self):
pass

def transform(self, nodes: ast.Module) -> None:
"""
This call should only happen once asttoken has run its magic
Expand All @@ -26,31 +23,3 @@ def transform(self, nodes: ast.Module) -> None:
node.end_col_offset = node.last_token.end[1] # type: ignore
# if isinstance(node, ast.ListComp):
node.col_offset = node.first_token.start[1] # type: ignore

def transform_inhouse(self, nodes: ast.Module) -> None:
curr_line_start: int = -1
curr_line_offset: int = -1
prev_line_start: int = -1
prev_line_offset: int = -1
prev_node = None
node: ast.AST
# TODO check if the ast type is a Module instead of simply relying on mypy
for node in ast.walk(nodes):
if not hasattr(node, "lineno"):
continue

curr_line_start = node.lineno
curr_line_offset = node.col_offset
if prev_node is not None:
prev_node.end_lineno = max( # type: ignore
prev_line_start, curr_line_start - 1
)
if prev_line_start == curr_line_start:
prev_node.end_col_offset = max(
prev_line_offset, curr_line_offset - 1
)
else:
prev_node.end_col_offset = -1
prev_node = node
prev_line_start = curr_line_start
prev_line_offset = curr_line_offset
39 changes: 19 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
alabaster==0.7.12
altair==4.2.0
anyio==3.4.0
anyio==3.5.0
appnope==0.1.2
argcomplete==2.0.0
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
astor==0.8.1
Expand All @@ -27,7 +26,7 @@ coveralls==3.3.1
cramjam==2.5.0
cycler==0.11.0
debugpy==1.5.1
decorator==5.1.0
decorator==5.1.1
defusedxml==0.7.1
distlib==0.3.4
docopt==0.6.2
Expand All @@ -39,54 +38,54 @@ fastparquet==0.7.2
filelock==3.4.2
flake8==4.0.1
fonttools==4.28.5
fsspec==2021.11.1
fsspec==2022.1.0
graphviz==0.19.1
greenlet==1.1.2
identify==2.4.1
identify==2.4.4
idna==3.3
imagesize==1.3.0
importlib-metadata==4.2.0
importlib-resources==5.4.0
iniconfig==1.1.1
ipykernel==6.6.1
ipykernel==6.7.0
ipython==7.31.0
ipython-genutils==0.2.0
isort==5.10.1
jedi==0.18.1
Jinja2==3.0.3
joblib==1.1.0
json5==0.9.6
jsonschema==4.3.3
jsonschema==4.4.0
jupyter-client==7.1.0
jupyter-core==4.9.1
jupyter-server==1.13.1
jupyterlab==3.2.5
jupyter-server==1.13.3
jupyterlab==3.2.8
jupyterlab-pygments==0.1.2
jupyterlab-server==2.10.2
jupyterlab-server==2.10.3
kiwisolver==1.3.2
MarkupSafe==2.0.1
matplotlib==3.5.1
matplotlib-inline==0.1.3
mccabe==0.6.1
mistune==0.8.4
mock==4.0.3
mypy==0.910
mypy==0.931
mypy-extensions==0.4.3
nbclassic==0.3.4
nbclient==0.5.9
nbclassic==0.3.5
nbclient==0.5.10
nbconvert==6.4.0
nbformat==5.1.3
nbval==0.9.6
nest-asyncio==1.5.4
networkx==2.6.3
nodeenv==1.6.0
notebook==6.4.6
notebook==6.4.7
numpy==1.21.5
packaging==21.3
pandas==1.3.5
pandocfilters==1.5.0
parso==0.8.3
path==16.2.0
path==16.3.0
path.py==12.5.0
pathspec==0.9.0
pdbpp==0.10.3
Expand All @@ -106,7 +105,7 @@ pycodestyle==2.8.0
pycparser==2.21
pydantic==1.9.0
pyflakes==2.4.0
Pygments==2.11.1
Pygments==2.11.2
PyOpenGL==3.1.5
pyparsing==3.0.6
pyrepl==0.9.0
Expand All @@ -123,7 +122,7 @@ pytz==2021.3
PyYAML==6.0
pyzmq==22.3.0
requests==2.27.1
rich==10.16.2
rich==11.0.0
scikit-learn==1.0.2
scipy==1.7.3
scour==0.38.2
Expand Down Expand Up @@ -154,10 +153,10 @@ tomli==1.2.3
toolz==0.11.2
tornado==6.1
traitlets==5.1.1
typed-ast==1.4.3
types-PyYAML==6.0.1
typed-ast==1.5.1
types-PyYAML==6.0.3
typing_extensions==4.0.1
urllib3==1.26.7
urllib3==1.26.8
virtualenv==20.13.0
wcwidth==0.2.5
webencodings==0.5.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def version(path):
"flake8",
"fastparquet",
"syrupy==1.4.5",
"mypy<0.920",
"mypy",
"isort",
"pytest",
"matplotlib",
Expand Down
Loading