From: whitequark Date: Sun, 26 May 2019 10:42:52 +0000 (+0000) Subject: hdl.ir: silence unused elaboratable warning on interpreter crash. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e96599748956162022045a21a6edeb44a27bbbbf;p=nmigen.git hdl.ir: silence unused elaboratable warning on interpreter crash. --- 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