From c593577a4a90b9c806c744b151efcb4e6b052aa4 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sat, 3 Apr 2010 15:54:36 +0000 Subject: Merged revisions 79674 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79674 | mark.dickinson | 2010-04-03 15:05:10 +0100 (Sat, 03 Apr 2010) | 3 lines Issue #8300: Let struct.pack use __index__ to convert and pack non-integers. Based on a patch by Meador Inge. ........ --- Doc/library/struct.rst | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Doc/library/struct.rst') diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index bee154f07a..ee949d9f60 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -119,6 +119,15 @@ Notes: the platform C compiler supports C :ctype:`long long`, or, on Windows, :ctype:`__int64`. They are always available in standard modes. +(4) + When attempting to pack a non-integer using any of the integer conversion + codes, if the non-integer has a :meth:`__index__` method then that method is + called to convert the argument to an integer before packing. + + .. versionchanged:: 3.2 + Use of the :meth:`__index__` method for non-integers is new in 3.2. + + A format character may be preceded by an integral repeat count. For example, the format string ``'4h'`` means exactly the same as ``'hhhh'``. -- cgit v1.2.1