Repository: iris-hep/func_adl

Issue:
The `len` call generates a type error
`len` is assumed to be float... Ops... Should not be.

First seen [here](https://github.com/iris-hep/idap-200gbps-atlas/issues/129)

Discussion:
codecov-commenter: ## [Codecov](https://app.codecov.io/gh/iris-hep/func_adl/pull/151?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 96.94%. Comparing base [(`29a3406`)](https://app.codecov.io/gh/iris-hep/func_adl/commit/29a3406bb2207b1433ec0e5ed9d13ccbc9b9c434?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep) to head [(`b51dae6`)](https://app.codecov.io/gh/iris-hep/func_adl/commit/b51dae6cc339a3ffddd4894f7b8c4c3462cc731a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #151   +/-   ##
=======================================
  Coverage   96.93%   96.94%           
=======================================
  Files          15       15           
  Lines        1338     1340    +2     
=======================================
+ Hits         1297     1299    +2     
  Misses         41       41           
```

| [Flag](https://app.codecov.io/gh/iris-hep/func_adl/pull/151/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep) | Coverage Δ | |
|---|---|---|
| [unittests](https://app.codecov.io/gh/iris-hep/func_adl/pull/151/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep) | `96.94% <100.00%> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep#carryforward-flags-in-the-pull-request-comment) to find out more.

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/iris-hep/func_adl/pull/151?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iris-hep).


Patch:
diff --git a/func_adl/type_based_replacement.py b/func_adl/type_based_replacement.py
index cfc7563..e8d94e5 100644
--- a/func_adl/type_based_replacement.py
+++ b/func_adl/type_based_replacement.py
@@ -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()


Test patch:
diff --git a/tests/test_type_based_replacement.py b/tests/test_type_based_replacement.py
index a2641f5..520cc53 100644
--- a/tests/test_type_based_replacement.py
+++ b/tests/test_type_based_replacement.py
@@ -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)