Skip to content

Commit

Permalink
Test that triggers the len error (#151)
Browse files Browse the repository at this point in the history
* Test that triggers the `len` error

* Added the dummy function for `len` for type checking
  • Loading branch information
gordonwatts authored Sep 12, 2024
1 parent 29a3406 commit b67b122
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions func_adl/type_based_replacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def _load_default_global_functions():
# TODO: Add in other functions

def my_abs(x: float) -> float: ... # noqa
def my_len(x: Iterable) -> int: ... # noqa

_global_functions["abs"] = _FuncAdlFunction("abs", my_abs, None)
_global_functions["len"] = _FuncAdlFunction("len", my_len, None)


_load_default_global_functions()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_type_based_replacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ def test_collection_First(caplog):
assert len(caplog.text) == 0


def test_collection_len(caplog):
"Make sure `len` is properly typed"
s = ast_lambda("len(e.Jets('default'))")
objs = ObjectStream[Event](ast.Name(id="e", ctx=ast.Load()))

new_objs, new_s, expr_type = remap_by_types(objs, "e", Event, s)

assert expr_type == int
assert len(caplog.text) == 0


def test_collection_Custom_Method_int(caplog):
"A custom collection method not pre-given"
caplog.set_level(logging.WARNING)
Expand Down

0 comments on commit b67b122

Please sign in to comment.