-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/nmigen/nmigen
- Loading branch information
Showing
16 changed files
with
245 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sys | ||
import warnings | ||
|
||
from ._utils import get_linter_option | ||
|
||
|
||
__all__ = ["UnusedMustUse", "MustUse"] | ||
|
||
|
||
class UnusedMustUse(Warning): | ||
pass | ||
|
||
|
||
class MustUse: | ||
_MustUse__silence = False | ||
_MustUse__warning = UnusedMustUse | ||
|
||
def __new__(cls, *args, src_loc_at=0, **kwargs): | ||
frame = sys._getframe(1 + src_loc_at) | ||
self = super().__new__(cls) | ||
self._MustUse__used = False | ||
self._MustUse__context = dict( | ||
filename=frame.f_code.co_filename, | ||
lineno=frame.f_lineno, | ||
source=self) | ||
return self | ||
|
||
def __del__(self): | ||
if self._MustUse__silence: | ||
return | ||
if hasattr(self, "_MustUse__used") and not self._MustUse__used: | ||
if get_linter_option(self._MustUse__context["filename"], | ||
self._MustUse__warning.__name__, bool, True): | ||
warnings.warn_explicit( | ||
"{!r} created but never used".format(self), self._MustUse__warning, | ||
**self._MustUse__context) | ||
|
||
|
||
_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. | ||
MustUse._MustUse__silence = True | ||
_old_excepthook(type, value, traceback) | ||
sys.excepthook = _silence_elaboratable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.