|
42 | 42 | from codeflash.tracing.replay_test import create_trace_replay_test |
43 | 43 | from codeflash.tracing.tracing_utils import FunctionModules |
44 | 44 | from codeflash.verification.verification_utils import get_test_file_path |
| 45 | +import contextlib |
45 | 46 |
|
46 | 47 | if TYPE_CHECKING: |
47 | 48 | from types import FrameType, TracebackType |
@@ -266,14 +267,20 @@ def tracer_logic(self, frame: FrameType, event: str) -> None: |
266 | 267 | class_name = None |
267 | 268 | arguments = frame.f_locals |
268 | 269 | 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__ |
277 | 284 | except: # noqa: E722 |
278 | 285 | # someone can override the getattr method and raise an exception. I'm looking at you wrapt |
279 | 286 | return |
|
0 commit comments