Skip to content

Commit 9ab0f60

Browse files
committed
Replace use of astunparse package with ast.unparse from the stdlib
Signed-off-by: Avi Shinnar <shinnar@us.ibm.com>
1 parent c2130d1 commit 9ab0f60

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[settings]
2-
known_third_party = ConfigSpace,aif360,astunparse,autoai_libs,black,graphviz,h5py,hyperopt,imblearn,jsonschema,jsonsubschema,lightgbm,numpy,pandas,pytest,pytorch_pretrained_bert,scipy,setuptools,sklearn,smac,spacy,sphinx_rtd_theme,tensorflow,tensorflow_hub,torch,torchvision,xgboost
2+
known_third_party = ConfigSpace,aif360,autoai_libs,black,graphviz,h5py,hyperopt,imblearn,jsonschema,jsonsubschema,lightgbm,numpy,pandas,pytest,pytorch_pretrained_bert,scipy,setuptools,sklearn,smac,spacy,sphinx_rtd_theme,tensorflow,tensorflow_hub,torch,torchvision,xgboost
33
profile = black

lale/expressions.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
from copy import deepcopy
2525
from typing import Any, Dict, Literal, Optional, Union, overload
2626

27-
import astunparse
28-
2927
AstLits = (ast.Num, ast.Str, ast.List, ast.Tuple, ast.Set, ast.Dict, ast.Constant)
3028
AstLit = Union[ast.Num, ast.Str, ast.List, ast.Tuple, ast.Set, ast.Dict, ast.Constant]
3129
AstExprs = (
@@ -229,7 +227,7 @@ def __ne__(self, other):
229227
return False
230228

231229
def __str__(self) -> str:
232-
result = astunparse.unparse(self._expr).strip()
230+
result = ast.unparse(self._expr).strip()
233231
if isinstance(self._expr, (ast.UnaryOp, ast.BinOp, ast.Compare, ast.BoolOp)):
234232
if result.startswith("(") and result.endswith(")"):
235233
result = result[1:-1]
@@ -585,7 +583,7 @@ def _it_column(expr):
585583
return expr.attr
586584
else:
587585
raise ValueError(
588-
f"Illegal {astunparse.unparse(expr)}. Only the access to `it` is supported"
586+
f"Illegal {ast.unparse(expr)}. Only the access to `it` is supported"
589587
)
590588
elif isinstance(expr, ast.Subscript):
591589
if isinstance(expr.slice, ast.Constant) or (
@@ -600,15 +598,15 @@ def _it_column(expr):
600598
return v.s
601599
else:
602600
raise ValueError(
603-
f"Illegal {astunparse.unparse(expr)}. Only the access to `it` is supported"
601+
f"Illegal {ast.unparse(expr)}. Only the access to `it` is supported"
604602
)
605603
else:
606604
raise ValueError(
607-
f"Illegal {astunparse.unparse(expr)}. Only the access to `it` is supported"
605+
f"Illegal {ast.unparse(expr)}. Only the access to `it` is supported"
608606
)
609607
else:
610608
raise ValueError(
611-
f"Illegal {astunparse.unparse(expr)}. Only the access to `it` is supported"
609+
f"Illegal {ast.unparse(expr)}. Only the access to `it` is supported"
612610
)
613611

614612

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"pandas",
5353
"packaging",
5454
"decorator",
55-
"astunparse",
5655
"typing-extensions",
5756
]
5857

test/test_core_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ def test_transformers(self):
7676

7777
class TestUnparseExpr(unittest.TestCase):
7878
def test_unparse_const38(self):
79-
import astunparse
79+
import ast
8080

8181
from lale.expressions import it
8282

8383
test_expr = it.hello["hi"]
84-
str(astunparse.unparse(test_expr._expr))
84+
str(ast.unparse(test_expr._expr))
8585

8686

8787
class TestOperatorWithoutSchema(unittest.TestCase):

0 commit comments

Comments
 (0)