Skip to content

Commit a2be746

Browse files
Essozclaude
andcommitted
fix: suppress deprecation warnings during attribute probing in dumper
safe_getattr() iterates all attributes of instrumented objects; some (e.g. torchvision dataset's .test_data) fire warnings.warn() on access. Wrap getattr in warnings.catch_warnings(simplefilter=ignore) so third-party deprecation warnings don't leak to the user's stderr. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e8ec62e commit a2be746

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

traincheck/instrumentor/dumper.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,15 @@ class NOT_FOUND:
316316

317317

318318
def safe_getattr(obj, attr_name):
319+
import warnings
320+
319321
try:
320-
attr = getattr(obj, attr_name, NOT_FOUND)
321-
if attr is NOT_FOUND:
322-
if issubclass(type(obj), dict):
323-
attr = dict.get(obj, attr_name, NOT_FOUND)
322+
with warnings.catch_warnings():
323+
warnings.simplefilter("ignore")
324+
attr = getattr(obj, attr_name, NOT_FOUND)
325+
if attr is NOT_FOUND:
326+
if issubclass(type(obj), dict):
327+
attr = dict.get(obj, attr_name, NOT_FOUND)
324328
return attr
325329
except Exception:
326330
return NOT_FOUND

0 commit comments

Comments
 (0)