[pypy-issue] [issue1177] The empty string is a new object every time

Kevin Duffy tracker at bugs.pypy.org
Thu Jun 14 02:47:49 CEST 2012


New submission from Kevin Duffy <duffy151+pypy at gmail.com>:

It looks like the empty string is allocated anew every time it's used:

>uname -v
Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-
1699.26.8~1/RELEASE_X86_64
>pypy --version
Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54)
[PyPy 1.9.0 with GCC 4.2.1]
>pypy
Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54)
[PyPy 1.9.0 with GCC 4.2.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``we have no anti-impossible stick
that makes sure that all your programs halt''
>>>> id('')
4356814232
>>>> id('')
4356814256
>>>> id('')
4356814280
>>>> id('')
4356814304
>>>> id('')
4356814328
>


Compare that with CPython:

>python --version
Python 2.7.3
>python
Python 2.7.3 (default, Apr 13 2012, 11:23:14) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.2.41)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> id('')
4517287176
>>> id('')
4517287176
>>> id('')
4517287176
>>> id('')
4517287176
>>> id('')
4517287176
>>> 


1) Isn't this inefficient?
2) This is valid BUT it does break a CPython idiom where (x == '' and x is '') is 
True. I.e., people often write "x is ''" when 
they mean x == ''. This should at least be noted in the first page of 
compatibility notes.

----------
messages: 4439
nosy: duffy151, pypy-issue
priority: performance bug
status: unread
title: The empty string is a new object every time

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1177>
________________________________________


More information about the pypy-issue mailing list