Skip to content
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

Test that triggers the len error #151

Merged
merged 2 commits into from
Sep 12, 2024
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
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
Loading