[Python-Dev] Returning int instead of long from struct when possible for performance (original) (raw)

Tim Peters tim.peters at gmail.com
Fri May 26 01:05:53 CEST 2006


[Bob Ippolito]

... Unfortunately, this change to the struct module slightly alters the documented API for the following format codes: I, L, q, Q. Currently it is documented that those format codes will always return longs, regardless of their value.

I view that more as having documented the CPython implementation du jour than as documenting the language. IOW, it was a doc bug <0.5 wink>.

I've prototyped this change on the trunk (behind a currently undefined PYUSEINTWHENPOSSIBLE macro). The standard library test suite passes with this enabled, but it would break any doctests in third party code that check the result of an unpack operation with one of those format codes. Given the interchangeability of int and long, I don't foresee any other complications with this change.

Thoughts?

+1, and for 2.5. Even int() doesn't always return an int anymore, and it's just stupid to bear the burden of an unbounded long when it's not really needed. As to doctest breakage, I'm wholly unsympathetic to any doctest user except me, and I don't have any doctests that would break. So that's a total non-issue :-)



More information about the Python-Dev mailing list