Skip to content

Commit

Permalink
Merge pull request #54 from sola-st/aryaz/filters
Browse files Browse the repository at this point in the history
Fixed issue with filters and repr
  • Loading branch information
AryazE authored Mar 10, 2024
2 parents 7aa6c43 + 0fcd802 commit 1bf813f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dynapyt/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def filtered(func, f, args):
fltr = docs[start + len(START) : end].strip()
patterns = fltr.split(" -> ")[1].split(SEPERATOR)
if fltr.startswith("only ->") and any(
[getattr(arg, "__name__", repr(arg)) in patterns for arg in sub_args]
[getattr(arg, "__name__", None) in patterns for arg in sub_args]
):
return False
elif fltr.startswith("ignore ->") and any(
[getattr(arg, "__name__", repr(arg)) in patterns for arg in sub_args]
[getattr(arg, "__name__", None) in patterns for arg in sub_args]
):
return True
docs = docs[end + len(END) :].lstrip()
Expand Down
14 changes: 14 additions & 0 deletions tests/filters/repr/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from dynapyt.analyses.BaseAnalysis import BaseAnalysis
from dynapyt.instrument.filters import ignore


class Analysis(BaseAnalysis):
def begin_execution(self):
print("begin execution")

def end_execution(self):
print("end execution")

@ignore(patterns=["foo"])
def pre_call(self, dyn_ast, iid, function, pos_args, kw_args):
print(f"pre call at {iid}")
7 changes: 7 additions & 0 deletions tests/filters/repr/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
begin execution
pre call at 3
pre call at 4
pre call at 1
pre call at 5
X
end execution
10 changes: 10 additions & 0 deletions tests/filters/repr/program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class X:
def __repr__(self):
return self.__str__()

def __str__(self) -> str:
return "X"


x = X()
print(repr(x))

0 comments on commit 1bf813f

Please sign in to comment.