Kaydet (Commit) 5fd3af24 authored tarafından Mark Dickinson's avatar Mark Dickinson

Issue #1523: Remove deprecated overflow masking in struct module, and

make sure that out-of-range values consistently raise struct.error.
üst bb3895cf
......@@ -26,12 +26,8 @@ else:
try:
import _struct
except ImportError:
PY_STRUCT_RANGE_CHECKING = 0
PY_STRUCT_OVERFLOW_MASKING = 1
PY_STRUCT_FLOAT_COERCE = 2
else:
PY_STRUCT_RANGE_CHECKING = getattr(_struct, '_PY_STRUCT_RANGE_CHECKING', 0)
PY_STRUCT_OVERFLOW_MASKING = getattr(_struct, '_PY_STRUCT_OVERFLOW_MASKING', 0)
PY_STRUCT_FLOAT_COERCE = getattr(_struct, '_PY_STRUCT_FLOAT_COERCE', 0)
def string_reverse(s):
......@@ -54,20 +50,6 @@ def with_warning_restore(func):
return func(*args, **kw)
return decorator
@with_warning_restore
def deprecated_err(func, *args):
try:
func(*args)
except (struct.error, OverflowError):
pass
except DeprecationWarning:
if not PY_STRUCT_OVERFLOW_MASKING:
raise TestFailed, "%s%s expected to raise DeprecationWarning" % (
func.__name__, args)
else:
raise TestFailed, "%s%s did not raise error" % (
func.__name__, args)
class StructTest(unittest.TestCase):
@with_warning_restore
......@@ -289,7 +271,7 @@ class StructTest(unittest.TestCase):
'\x01' + got)
else:
# x is out of range -- verify pack realizes that.
deprecated_err(pack, format, x)
self.assertRaises(struct.error, pack, format, x)
def run(self):
from random import randrange
......
......@@ -1173,6 +1173,10 @@ C-API
Extension Modules
-----------------
- Issue #1523: Remove deprecated overflow wrapping for struct.pack
with an integer format code ('bBhHiIlLqQ'). Packing an out-of-range
integer now consistently raises struct.error.
- Issues #1530559, #1741130: Fix various struct.pack inconsistencies
for the integer formats ('bBhHiIlLqQ'). In the following, '*'
represents any of '=', '<', '>'.
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment