Re: [Python-Dev] sys.intern should work on bytes

2013-09-23 Thread Hrvoje Niksic
On 09/20/2013 06:50 PM, PJ Eby wrote: On Fri, Sep 20, 2013 at 9:54 AM, Jesus Cea wrote: Why str/bytes doesn't support weakrefs, beside memory use? The typical use case for weakrefs is to break reference cycles, Another typical use case, and the prime reason why languages without reference

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread PJ Eby
On Fri, Sep 20, 2013 at 9:54 AM, Jesus Cea wrote: > Why str/bytes doesn't support weakrefs, beside memory use? The typical use case for weakrefs is to break reference cycles, but str and bytes can't *be* part of a reference cycle, so outside of interning-like use cases, there's no need for weakre

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Benjamin Peterson
2013/9/20 Jesus Cea : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 20/09/13 15:44, Antoine Pitrou wrote: > >> Yes. The main difference is that sys.intern() will remove the >> interned strings when every external reference vanishes. It >> requires either weakref'ability (which both str a

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Jesus Cea
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 20/09/13 15:44, Antoine Pitrou wrote: > Yes. The main difference is that sys.intern() will remove the > interned strings when every external reference vanishes. It > requires either weakref'ability (which both str and bytes lack) or > special coope

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Antoine Pitrou
Le Fri, 20 Sep 2013 15:33:05 +0200, Jesus Cea a écrit : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 20/09/13 14:15, Antoine Pitrou wrote: > > From http://docs.python.org/3.3/library/sys.html#sys.intern > > > > """sys.intern(string) > > > > Enter string in the table of “interned” st

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Antoine Pitrou
Le Fri, 20 Sep 2013 15:36:45 +0200, Jesus Cea a écrit : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 20/09/13 15:31, Antoine Pitrou wrote: > > sys.intern is an internal interpreter optimization and should be > > orthogonal to pickling. If pickle can't detect already-seen bytes > > o

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Jesus Cea
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 20/09/13 15:31, Antoine Pitrou wrote: > sys.intern is an internal interpreter optimization and should be > orthogonal to pickling. If pickle can't detect already-seen bytes > object, then you may file an improvement request on the bug > tracker.

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Benjamin Peterson
Well, the pickler should memoize bytes objects if you have lots of the same one in a pickle... 2013/9/20 Jesus Cea : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 20/09/13 14:04, Victor Stinner wrote: >> What would you be the use case of interned bytes objets? > > Performance and memory

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Jesus Cea
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 20/09/13 14:15, Antoine Pitrou wrote: > From http://docs.python.org/3.3/library/sys.html#sys.intern > > """sys.intern(string) > > Enter string in the table of “interned” strings and return the > interned string [...]""" > > > In Python 3 contex

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Antoine Pitrou
Le Fri, 20 Sep 2013 15:14:37 +0200, Jesus Cea a écrit : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 20/09/13 14:04, Victor Stinner wrote: > > What would you be the use case of interned bytes objets? > > Performance and memory. Pickle sizes (my particular issue now). sys.intern is a

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Jesus Cea
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 20/09/13 14:04, Victor Stinner wrote: > What would you be the use case of interned bytes objets? Performance and memory. Pickle sizes (my particular issue now). - -- Jesús Cea Avión _/_/ _/_/_/_/_/_/ j...@jcea

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Antoine Pitrou
Le Fri, 20 Sep 2013 13:19:24 +0200, Jesus Cea a écrit : > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > """ > sys.intern(b'12121212') > Traceback (most recent call last): > File "", line 1, in > TypeError: must be str, not bytes > """ > > I wonder why. From http://docs.python.org/3.3/l

Re: [Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Victor Stinner
2013/9/20 Jesus Cea : > """ > sys.intern(b'12121212') > Traceback (most recent call last): > File "", line 1, in > TypeError: must be str, not bytes > """ > > I wonder why. Intern strings optimize dictionary lookup. In Python 3, most dictionaries use str keys (ex: __dict__ of classes). What wo

[Python-Dev] sys.intern should work on bytes

2013-09-20 Thread Jesus Cea
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 """ sys.intern(b'12121212') Traceback (most recent call last): File "", line 1, in TypeError: must be str, not bytes """ I wonder why. - -- Jesús Cea Avión _/_/ _/_/_/_/_/_/ j...@jcea.es - http://www.jcea.es/