Merge pull request #4919 from blueyed/opt

Optimize TracebackEntry.ishidden
This commit is contained in:
Daniel Hahler 2019-03-14 16:37:57 +01:00 committed by GitHub
commit 951e07d71d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 12 deletions

View File

@ -241,25 +241,20 @@ class TracebackEntry(object):
def ishidden(self): def ishidden(self):
""" return True if the current frame has a var __tracebackhide__ """ return True if the current frame has a var __tracebackhide__
resolving to True resolving to True.
If __tracebackhide__ is a callable, it gets called with the If __tracebackhide__ is a callable, it gets called with the
ExceptionInfo instance and can decide whether to hide the traceback. ExceptionInfo instance and can decide whether to hide the traceback.
mostly for internal use mostly for internal use
""" """
try: f = self.frame
tbh = self.frame.f_locals["__tracebackhide__"] tbh = f.f_locals.get(
except KeyError: "__tracebackhide__", f.f_globals.get("__tracebackhide__", False)
try: )
tbh = self.frame.f_globals["__tracebackhide__"] if tbh and callable(tbh):
except KeyError:
return False
if callable(tbh):
return tbh(None if self._excinfo is None else self._excinfo()) return tbh(None if self._excinfo is None else self._excinfo())
else: return tbh
return tbh
def __str__(self): def __str__(self):
try: try: