Commit ca8d3909 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #83 from zopefoundation/issue79

Use operator.index to avoid DeprecationWarning on Python 2
parents 023d96a7 4debe1bb
......@@ -16,6 +16,7 @@
from struct import Struct
from struct import error as struct_error
from operator import index
from persistent import Persistent
......@@ -1503,12 +1504,8 @@ int_pack, int_unpack = _packer_unpacker('i')
def to_int(self, v):
try:
# XXX Python 2.6 doesn't truncate, it spews a warning.
if not int_unpack(int_pack(v))[0] == v: #pragma: no cover
raise TypeError('32-bit integer expected')
except (struct_error,
OverflowError, #PyPy
):
int_pack(index(v))
except (struct_error, TypeError):
raise TypeError('32-bit integer expected')
return int(v)
......@@ -1527,14 +1524,8 @@ long_pack, long_unpack = _packer_unpacker('q')
def to_long(self, v):
try:
# XXX Python 2.6 doesn't truncate, it spews a warning.
if not long_unpack(long_pack(v))[0] == v: #pragma: no cover
if isinstance(v, int_types):
raise ValueError("Value out of range", v)
raise TypeError('64-bit integer expected')
except (struct_error,
OverflowError, #PyPy
):
long_pack(index(v))
except (struct_error, TypeError):
if isinstance(v, int_types):
raise ValueError("Value out of range", v)
raise TypeError('64-bit integer expected')
......
......@@ -14,7 +14,10 @@
- Respect the ``PURE_PYTHON`` environment variable at runtime even if
the C extensions are available. See
https://github.com/zopefoundation/BTrees/issues/78
- Always attempt to build the C extensions, but make their success optional.
- Always attempt to build the C extensions, but make their success
optional.
- Fix a ``DeprecationWarning`` that could come from I and L objects in
Python 2 in pure-Python mode. See https://github.com/zopefoundation/BTrees/issues/79
4.4.1 (2017-01-24)
------------------
......
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