summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-03 14:05:10 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-04-03 14:05:10 (GMT)
commit4846a8e828e345772de53aa410fcabe6a4aae772 (patch)
tree03d81d42998c42f59482f15001446c36ba70211e /Doc
parentae509520de5a0321f58c79afffad10ae59dae8b9 (diff)
downloadcpython-4846a8e828e345772de53aa410fcabe6a4aae772.zip
cpython-4846a8e828e345772de53aa410fcabe6a4aae772.tar.gz
cpython-4846a8e828e345772de53aa410fcabe6a4aae772.tar.bz2
Issue #8300: Let struct.pack use __index__ to convert and pack non-integers.
Based on a patch by Meador Inge.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/struct.rst11
1 files changed, 8 insertions, 3 deletions
diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst
index 3664e35..ea6b416 100644
--- a/Doc/library/struct.rst
+++ b/Doc/library/struct.rst
@@ -125,9 +125,14 @@ Notes:
(3)
When attempting to pack a non-integer using any of the integer conversion
- codes, the non-integer's :meth:`__int__` method (if present) will be called
- to convert to an integer before packing. However, this behaviour is
- deprecated, and will raise :exc:`DeprecationWarning`.
+ codes, if the non-integer has a :meth:`__index__` method then that method is
+ called to convert the argument to an integer before packing. If no
+ :meth:`__index__` method exists, or the call to :meth:`__index__` raises
+ :exc:`TypeError`, then the :meth:`__int__` method is tried. However, the use
+ of `__int__` is deprecated, and will raise :exc:`DeprecationWarning`.
+
+ .. versionchanged:: 2.7
+ Use of the :meth:`__index__` method for non-integers is new in 2.7.
.. versionchanged:: 2.7
Prior to version 2.7, not all integer conversion codes would use the