Issue2138

classification
Title: hex() function output is different than CPython
Type: Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: JonathanFeinberg, jeff.allen
Priority: Keywords:

Created on 2014-05-09.13:19:54 by JonathanFeinberg, last changed 2014-05-09.18:47:49 by jeff.allen.

Files
File name Uploaded Description Edit Remove
unnamed JonathanFeinberg, 2014-05-09.18:22:34
Messages
msg8348 (view) Author: Jonathan Feinberg (JonathanFeinberg) Date: 2014-05-09.13:19:53
In CPython:

hex(0xFF0000FF) -> 0xff0000ff

In Jython:

hex(0xFF0000FF) -> 0xff0000ffL

It may be that ints are inappropriately promoted to longs.
msg8349 (view) Author: Jeff Allen (jeff.allen) Date: 2014-05-09.17:05:06
0xff0000ff *is* a long. Are you perhaps comparing with Python 3?

>python
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 0xff0000ff
4278190335L
>>> hex(0xff0000ff)
'0xff0000ffL'
>>> format(0xff0000ff, "#x")
'0xff0000ff'
>>>
msg8350 (view) Author: Jonathan Feinberg (JonathanFeinberg) Date: 2014-05-09.17:35:06
$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0xff0000ff
4278190335
>>> hex(0xff0000ff)
'0xff0000ff'
>>>

Looks like it's an unspecified behavior!

On Fri, May 9, 2014 at 1:05 PM, Jeff Allen <report@bugs.jython.org> wrote:

>
> Jeff Allen added the comment:
>
> 0xff0000ff *is* a long. Are you perhaps comparing with Python 3?
>
> >python
> Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 0xff0000ff
> 4278190335L
> >>> hex(0xff0000ff)
> '0xff0000ffL'
> >>> format(0xff0000ff, "#x")
> '0xff0000ff'
> >>>
>
> ----------
> nosy: +jeff.allen
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue2138>
> _______________________________________
>
msg8351 (view) Author: Jeff Allen (jeff.allen) Date: 2014-05-09.18:08:15
A late addition to PEP 237 (http://legacy.python.org/dev/peps/pep-0237/) says:
    - hex() and oct() applied to longs will continue to produce a
      trailing 'L' until Python 3000.  The original text above wasn't
      clear about this, but since it didn't happen in Python 2.4 it
      was thought better to leave it alone.  BDFL pronouncement here:
          http://mail.python.org/pipermail/python-dev/2006-June/065918.html

When we aim for Python 2.7, we aim for the latest one, so this is right.
msg8352 (view) Author: Jonathan Feinberg (JonathanFeinberg) Date: 2014-05-09.18:22:34
Thanks, Jeff.
msg8353 (view) Author: Jeff Allen (jeff.allen) Date: 2014-05-09.18:47:49
Closing as the observed behaviour is conformant (albeit with a moving target).
History
Date User Action Args
2014-05-09 18:47:49jeff.allensetstatus: open -> closed
resolution: invalid
messages: + msg8353
versions: + Jython 2.7
2014-05-09 18:22:34JonathanFeinbergsetfiles: + unnamed
messages: + msg8352
2014-05-09 18:08:15jeff.allensetmessages: + msg8351
2014-05-09 18:04:47jeff.allensetfiles: - unnamed
2014-05-09 17:35:06JonathanFeinbergsetfiles: + unnamed
messages: + msg8350
2014-05-09 17:05:07jeff.allensetnosy: + jeff.allen
messages: + msg8349
2014-05-09 13:19:54JonathanFeinbergcreate