Skip to content

Commit

Permalink
Test that actually tickles the error
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwatts committed Oct 10, 2023
1 parent 6f68ef9 commit 2c4e2c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion func_adl/util_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import tokenize
from collections import defaultdict
from types import ModuleType
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, Union, cast

# Some functions to enable backwards compatibility.
Expand Down Expand Up @@ -333,7 +334,10 @@ def visit_Name(self, node: ast.Name) -> Any:
if node.id in self._lookup_dict:
v = self._lookup_dict[node.id]
if not callable(v):
return as_literal(self._lookup_dict[node.id])
# Modules should be sent on down to be dealt with by the
# backend.
if not isinstance(v, ModuleType):
return as_literal(v)
return node

def visit_Lambda(self, node: ast.Lambda) -> Any:
Expand Down
11 changes: 9 additions & 2 deletions tests/test_object_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,22 @@ def test_query_with_comprehensions():


def test_non_imported_function_call():
r = my_event().Select(lambda event: np.cos(event.MET_phi)).value() # NOQA
r = (
my_event()
.Select(lambda event: np.cos(event.MET_phi)) # type: ignore # noqa
.Where(lambda p: p > 0.0)
.value()
) # NOQA
assert isinstance(r, ast.AST)
assert "Attribute(value=Name(id='np', ctx=Load()), attr='cos', ctx=Load())" in ast.dump(r)


def test_imported_function_call():
import numpy as np

r = my_event().Select(lambda event: np.cos(event.MET_phi)).value()
r = my_event().Select(lambda event: np.cos(event.MET_phi)).Where(lambda p: p > 0.0).value()
assert isinstance(r, ast.AST)
assert "Attribute(value=Name(id='np', ctx=Load()), attr='cos', ctx=Load())" in ast.dump(r)


def test_bad_where():
Expand Down

0 comments on commit 2c4e2c7

Please sign in to comment.