From 0fcd802f98832297019bcc2def5056b04f46366e Mon Sep 17 00:00:00 2001 From: Aryaz Eghbali Date: Sun, 10 Mar 2024 16:54:18 +0100 Subject: [PATCH] Fixed issue with filters and repr --- src/dynapyt/runtime.py | 4 ++-- tests/filters/repr/analysis.py | 14 ++++++++++++++ tests/filters/repr/expected.txt | 7 +++++++ tests/filters/repr/program.py | 10 ++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/filters/repr/analysis.py create mode 100644 tests/filters/repr/expected.txt create mode 100644 tests/filters/repr/program.py diff --git a/src/dynapyt/runtime.py b/src/dynapyt/runtime.py index 0018dd6..1d68972 100644 --- a/src/dynapyt/runtime.py +++ b/src/dynapyt/runtime.py @@ -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() diff --git a/tests/filters/repr/analysis.py b/tests/filters/repr/analysis.py new file mode 100644 index 0000000..d8150b2 --- /dev/null +++ b/tests/filters/repr/analysis.py @@ -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}") diff --git a/tests/filters/repr/expected.txt b/tests/filters/repr/expected.txt new file mode 100644 index 0000000..0124346 --- /dev/null +++ b/tests/filters/repr/expected.txt @@ -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 \ No newline at end of file diff --git a/tests/filters/repr/program.py b/tests/filters/repr/program.py new file mode 100644 index 0000000..3123675 --- /dev/null +++ b/tests/filters/repr/program.py @@ -0,0 +1,10 @@ +class X: + def __repr__(self): + return self.__str__() + + def __str__(self) -> str: + return "X" + + +x = X() +print(repr(x))