[issue8300] Allow struct.pack to handle objects with an __index__ method.

2011-02-19 Thread Matt Joiner
Matt Joiner added the comment: Thanks Mark for clearing that up. I found this link to be useful in explaining the purpose of __index__: http://docs.python.org/release/2.5.1/whatsnew/pep-357.html I think the choice of allowing only __index__ was the right choice. -- _

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2011-02-19 Thread Mark Dickinson
Mark Dickinson added the comment: Because (arguably) we don't want to be able to pack non-integral floats (or Decimal instances, or ...) using integer formats: >>> import struct [56090 refs] >>> struct.pack('L', 2.3) Traceback (most recent call last): File "", line 1, in struct.error: requi

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2011-02-19 Thread Matt Joiner
Matt Joiner added the comment: Why isn't this implemented to work with __int__ as well? -- nosy: +anacrolix ___ Python tracker ___ ___

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-05 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks. -- status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-04 Thread Meador Inge
Meador Inge added the comment: Looks good to me. -- status: pending -> open ___ Python tracker ___ ___ Python-bugs-list mailing list U

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-04 Thread Mark Dickinson
Mark Dickinson added the comment: Merged to py3k in r79746. Meador, does this all look okay, now? -- resolution: -> accepted stage: patch review -> committed/rejected status: open -> pending ___ Python tracker __

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-04 Thread Mark Dickinson
Mark Dickinson added the comment: Committed (with some tabs in test_struct.py changed to spaces) to trunk in r79745. -- ___ Python tracker ___ __

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-04 Thread Mark Dickinson
Mark Dickinson added the comment: Probably both those conditions can't be satisfied; I'm wasn't sure what happened if something's __index__ method returned something other than an int or long. But now I bother to look at the source (in Objects/abstract.c) I see that there *is* already an ex

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Meador Inge
Meador Inge added the comment: I may be missing something subtle, but how can 'PyNumber_Index(v) != NULL' *and* '!PyInt_Check(v) && !PyLong_Check(v)' both be satisfied in the 'get_pylong' mods? It seems to me that 'PyNumber_Index' only returns non-NULL when the object being returned is an 'i

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Mark Dickinson
Mark Dickinson added the comment: Committed this patch to trunk in r79674. Will forward port to py3k. -- ___ Python tracker ___ ___ P

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Mark Dickinson
Changes by Mark Dickinson : -- priority: -> normal stage: test needed -> patch review ___ Python tracker ___ ___ Python-bugs-list mail

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Mark Dickinson
Mark Dickinson added the comment: That patch was a bit hasty in many respects; here's a better one. For 2.7, the scheme is as follows: when packing a non-integer with an integer format: (1) First __index__ is tried (2) If the __index__ method doesn't exist, or the call to __index__ raises

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Mark Dickinson
Mark Dickinson added the comment: Adding Meador Inge to nosy. -- nosy: +minge ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Mark Dickinson
Mark Dickinson added the comment: Here's a patch for trunk. It combines the docs and tests from Meador Inge's patch in issue 1530559 with a C-level change to get_pylong in Modules/struct.c. -- keywords: +patch versions: +Python 2.7 Added file: http://bugs.python.org/file16746/struct_i

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Mark Dickinson
Changes by Mark Dickinson : -- components: +Extension Modules stage: -> test needed type: -> feature request ___ Python tracker ___ _

[issue8300] Allow struct.pack to handle objects with an __index__ method.

2010-04-03 Thread Mark Dickinson
New submission from Mark Dickinson : In Python 2.7, struct.pack with an integer format can handle non-integers that provide an __int__ method (although this *does* raise a DeprecationWarning). Python 2.7a4+ (trunk:79659:79661, Apr 3 2010, 11:28:19) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)]