summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Gedminas <marius@gedmin.as>2020-04-10 16:12:04 +0300
committerMarius Gedminas <marius@gedmin.as>2020-04-10 16:12:04 +0300
commit7b60f2b3e2901d0d2aaa0e2f9078fd69516ffedb (patch)
treeccebd8ed613ebde4706b63809f1c58b1fee0874f
parent655ecd61c25a32d293cab7983852c8cef6562291 (diff)
downloadzope-exceptions-7b60f2b3e2901d0d2aaa0e2f9078fd69516ffedb.tar.gz
A better way to suppress unused import warnings
-rw-r--r--setup.cfg5
-rw-r--r--src/zope/exceptions/__init__.py12
-rw-r--r--src/zope/exceptions/exceptionformatter.py6
3 files changed, 15 insertions, 8 deletions
diff --git a/setup.cfg b/setup.cfg
index 16ddf23..2bece89 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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
diff --git a/src/zope/exceptions/__init__.py b/src/zope/exceptions/__init__.py
index 053f25b..84d1dd2 100644
--- a/src/zope/exceptions/__init__.py
+++ b/src/zope/exceptions/__init__.py
@@ -26,9 +26,15 @@ from zope.exceptions.exceptionformatter import format_exception
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):
@@ -40,3 +46,7 @@ else: # pragma: no cover
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',
+ ]
diff --git a/src/zope/exceptions/exceptionformatter.py b/src/zope/exceptions/exceptionformatter.py
index bc2e768..abf0ae7 100644
--- a/src/zope/exceptions/exceptionformatter.py
+++ b/src/zope/exceptions/exceptionformatter.py
@@ -174,7 +174,8 @@ class TextExceptionFormatter(object):
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:
@@ -206,7 +207,8 @@ class TextExceptionFormatter(object):
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: