Skip to content

Commit

Permalink
A better way to suppress unused import warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Apr 10, 2020
1 parent 655ecd6 commit 7b60f2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 0 additions & 5 deletions setup.cfg
Expand Up @@ -11,8 +11,3 @@ docs = easy_install zope.exceptions[docs]

[bdist_wheel]
universal = 1

[flake8]
extend-ignore = F401
# https://pep8.readthedocs.org/en/latest/intro.html#error-codes
# F401: ``module`` imported but unused
12 changes: 11 additions & 1 deletion src/zope/exceptions/__init__.py
Expand Up @@ -26,9 +26,15 @@
from zope.exceptions.exceptionformatter import print_exception
from zope.exceptions.exceptionformatter import extract_stack

__all__ = [
'DuplicationError', 'IDuplicationError', 'UserError', 'IUserError',
'format_exception', 'print_exception', 'extract_stack',
]


# avoid dependency on zope.security:
try:
import zope.security
import zope.security # noqa: suppress unused import warning from flake8
except ImportError as v: # pragma: no cover
# "ImportError: No module named security"
if 'security' not in str(v):
Expand All @@ -40,3 +46,7 @@
from zope.security.interfaces import IForbiddenAttribute
from zope.security.interfaces import Forbidden
from zope.security.interfaces import ForbiddenAttribute
__all__ += [
'IUnauthorized', 'Unauthorized', 'IForbidden', 'IForbiddenAttribute',
'Forbidden', 'ForbiddenAttribute',
]
6 changes: 4 additions & 2 deletions src/zope/exceptions/exceptionformatter.py
Expand Up @@ -174,7 +174,8 @@ def formatLastLine(self, exc_line):
return self.escape(exc_line)

def formatException(self, etype, value, tb):
# The next line provides a way to detect recursion.
# The next line provides a way to detect recursion. The 'noqa'
# comment disables a flake8 warning about the unused variable.
__exception_formatter__ = 1 # noqa
result = []
while tb is not None:
Expand Down Expand Up @@ -206,7 +207,8 @@ def extractStack(self, f=None):
except ZeroDivisionError:
f = sys.exc_info()[2].tb_frame.f_back

# The next line provides a way to detect recursion.
# The next line provides a way to detect recursion. The 'noqa'
# comment disables a flake8 warning about the unused variable.
__exception_formatter__ = 1 # noqa
result = []
while f is not None:
Expand Down

0 comments on commit 7b60f2b

Please sign in to comment.