Make BytesWarning->exception global, to ease use in integration tests.

This commit is contained in:
Itamar Turner-Trauring 2021-04-16 11:55:20 -04:00
parent 19a3481e5f
commit 61506f87bb
2 changed files with 16 additions and 7 deletions

View File

@ -8,7 +8,7 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
from future.utils import PY2 from future.utils import PY2, PY3
if PY2: if PY2:
# Don't import future str() so we don't break Foolscap serialization on Python 2. # Don't import future str() so we don't break Foolscap serialization on Python 2.
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401 from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401
@ -62,3 +62,18 @@ standard_library.install_aliases()
from ._monkeypatch import patch from ._monkeypatch import patch
patch() patch()
del patch del patch
# On Python 3, turn BytesWarnings into exceptions. This can have potential
# production impact... if BytesWarnings are actually present in the codebase.
# Given that this has been enabled before Python 3 Tahoe-LAFS was publicly
# released, no such code should exist, and this will ensure it doesn't get
# added either.
#
# Also note that BytesWarnings only happen if Python is run with -b option, so
# in practice this should only affect tests.
if PY3:
import warnings
# Error on BytesWarnings, to catch things like str(b""), but only for
# allmydata code.
warnings.filterwarnings("error", category=BytesWarning, module=".*allmydata.*")

View File

@ -24,7 +24,6 @@ from future.utils import PY2, PY3
if PY2: if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
import warnings
from traceback import extract_stack, format_list from traceback import extract_stack, format_list
from foolscap.pb import Listener from foolscap.pb import Listener
@ -33,11 +32,6 @@ from twisted.application import service
from foolscap.logging.incident import IncidentQualifier from foolscap.logging.incident import IncidentQualifier
if PY3:
# Error on BytesWarnings, to catch things like str(b""), but only for
# allmydata code.
warnings.filterwarnings("error", category=BytesWarning, module=".*allmydata.*")
class NonQualifier(IncidentQualifier, object): class NonQualifier(IncidentQualifier, object):
def check_event(self, ev): def check_event(self, ev):