Skip to content

Commit 4effd83

Browse files
committed
Easier to ask for forgiveness than permission
1 parent 8758a41 commit 4effd83

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

codeflash/tracer.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from codeflash.tracing.replay_test import create_trace_replay_test
4343
from codeflash.tracing.tracing_utils import FunctionModules
4444
from codeflash.verification.verification_utils import get_test_file_path
45+
import contextlib
4546

4647
if TYPE_CHECKING:
4748
from types import FrameType, TracebackType
@@ -266,14 +267,20 @@ def tracer_logic(self, frame: FrameType, event: str) -> None:
266267
class_name = None
267268
arguments = frame.f_locals
268269
try:
269-
if (
270-
"self" in arguments
271-
and hasattr(arguments["self"], "__class__")
272-
and hasattr(arguments["self"].__class__, "__name__")
273-
):
274-
class_name = arguments["self"].__class__.__name__
275-
elif "cls" in arguments and hasattr(arguments["cls"], "__name__"):
276-
class_name = arguments["cls"].__name__
270+
self_arg = arguments.get("self")
271+
if self_arg is not None:
272+
try:
273+
class_name = self_arg.__class__.__name__
274+
except AttributeError:
275+
cls_arg = arguments.get("cls")
276+
if cls_arg is not None:
277+
with contextlib.suppress(AttributeError):
278+
class_name = cls_arg.__name__
279+
else:
280+
cls_arg = arguments.get("cls")
281+
if cls_arg is not None:
282+
with contextlib.suppress(AttributeError):
283+
class_name = cls_arg.__name__
277284
except: # noqa: E722
278285
# someone can override the getattr method and raise an exception. I'm looking at you wrapt
279286
return

0 commit comments

Comments
 (0)