Skip to content

Commit cd33232

Browse files
authored
Merge pull request #190 from iris-hep:big/range
Make sure Range isn't Replaced
2 parents 2b760c4 + 791393a commit cd33232

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

func_adl/functions.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import ast
2-
from typing import Union, cast
2+
from typing import Union
33

44
from .object_stream import ObjectStream
5-
from .util_ast import as_ast, function_call
65

76

87
def Range(
98
lower_bound: Union[str, int, ast.AST], upper_bound: Union[str, int, ast.AST]
10-
) -> ObjectStream:
9+
) -> ObjectStream[int]:
1110
r"""
1211
Given the lower and upper bound return an object with the range of numbers, similar to python
1312
range
@@ -20,11 +19,5 @@ def Range(
2019
Return:
2120
2221
A new ObjectStream that contains the range of numbers
23-
2422
"""
25-
26-
return ObjectStream(
27-
function_call(
28-
"Range", [cast(ast.AST, as_ast(lower_bound)), cast(ast.AST, as_ast(upper_bound))]
29-
)
30-
)
23+
...

tests/test_util_ast.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,3 +1091,17 @@ def __init__(self, n):
10911091
check_ast(a)
10921092

10931093
assert "my_type" in str(e)
1094+
1095+
1096+
def test_Select_inline():
1097+
"Make sure nothing funny happens to Select"
1098+
r = parse_as_ast(lambda jets: jets.Select(lambda j: j.pt()))
1099+
assert "function_call" not in ast.unparse(r)
1100+
1101+
1102+
def test_Range_inline():
1103+
"Make sure nothing funny happens to Range"
1104+
from func_adl import Range
1105+
1106+
r = parse_as_ast(lambda jets: Range(1, 10).Select(lambda j: j + 1))
1107+
assert "function_call" not in ast.unparse(r)

0 commit comments

Comments
 (0)