From b0ba960296aac6dff8530fbf9b1693881d8b7e5f Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 26 May 2019 10:42:52 +0000 Subject: [PATCH] hdl.ir: silence unused elaboratable warning on interpreter crash. --- nmigen/hdl/ir.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nmigen/hdl/ir.py b/nmigen/hdl/ir.py index c462e7e..8836b25 100644 --- a/nmigen/hdl/ir.py +++ b/nmigen/hdl/ir.py @@ -14,6 +14,8 @@ __all__ = ["Elaboratable", "DriverConflict", "Fragment", "Instance"] class Elaboratable(metaclass=ABCMeta): + _Elaboratable__silence = False + def __new__(cls, *args, **kwargs): self = super().__new__(cls) self._Elaboratable__traceback = traceback.extract_stack()[:-1] @@ -21,6 +23,8 @@ class Elaboratable(metaclass=ABCMeta): return self def __del__(self): + if self._Elaboratable__silence: + return if hasattr(self, "_Elaboratable__used") and not self._Elaboratable__used: print("Elaboratable created but never used\n", "Traceback (most recent call last):\n", @@ -28,6 +32,15 @@ class Elaboratable(metaclass=ABCMeta): file=sys.stderr, sep="") +_old_excepthook = sys.excepthook +def _silence_elaboratable(type, value, traceback): + # Don't show anything if the interpreter crashed; that'd just obscure the exception + # traceback instead of helping. + Elaboratable._Elaboratable__silence = True + _old_excepthook(type, value, traceback) +sys.excepthook = _silence_elaboratable + + class DriverConflict(UserWarning): pass -- 2.30.2