Skip to content

Commit b67b122

Browse files
authored
Test that triggers the len error (#151)
* Test that triggers the `len` error * Added the dummy function for `len` for type checking
1 parent 29a3406 commit b67b122

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

func_adl/type_based_replacement.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ def _load_default_global_functions():
6161
# TODO: Add in other functions
6262

6363
def my_abs(x: float) -> float: ... # noqa
64+
def my_len(x: Iterable) -> int: ... # noqa
6465

6566
_global_functions["abs"] = _FuncAdlFunction("abs", my_abs, None)
67+
_global_functions["len"] = _FuncAdlFunction("len", my_len, None)
6668

6769

6870
_load_default_global_functions()

tests/test_type_based_replacement.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,17 @@ def test_collection_First(caplog):
341341
assert len(caplog.text) == 0
342342

343343

344+
def test_collection_len(caplog):
345+
"Make sure `len` is properly typed"
346+
s = ast_lambda("len(e.Jets('default'))")
347+
objs = ObjectStream[Event](ast.Name(id="e", ctx=ast.Load()))
348+
349+
new_objs, new_s, expr_type = remap_by_types(objs, "e", Event, s)
350+
351+
assert expr_type == int
352+
assert len(caplog.text) == 0
353+
354+
344355
def test_collection_Custom_Method_int(caplog):
345356
"A custom collection method not pre-given"
346357
caplog.set_level(logging.WARNING)

0 commit comments

Comments
 (0)