Re: [Python-Dev] Requesting that a class be a new-style class

2005-02-18 Thread Alex Martelli
On 2005 Feb 19, at 06:03, Nick Coghlan wrote: This is something I've typed way too many times: Py> class C(): File "", line 1 class C(): ^ SyntaxError: invalid syntax It's the asymmetry with functions that gets to me - defining a function with no arguments still requires parenthe

Re: [Python-Dev] license issues with profiler.py and md5.h/md5c.c

2005-02-18 Thread Gregory P. Smith
On Fri, Feb 18, 2005 at 10:06:24AM +0100, "Martin v. L?wis" wrote: > Donovan Baarda wrote: > >This patch keeps the current md5c.c, md5module.c files and adds the > >following; _hashopenssl.c, hashes.py, md5.py, sha.py. > [...] > >If all we wanted to do was fix the md5 module > > If we want to fix

Re: [Python-Dev] license issues with profiler.py and md5.h/md5c.c

2005-02-18 Thread Donovan Baarda
From: "Martin v. Löwis" <[EMAIL PROTECTED]> > Donovan Baarda wrote: > > This patch keeps the current md5c.c, md5module.c files and adds the > > following; _hashopenssl.c, hashes.py, md5.py, sha.py. > [...] > > If all we wanted to do was fix the md5 module > > If we want to fix the licensing issues

Re: [Python-Dev] builtin_id() returns negative numbers

2005-02-18 Thread Donovan Baarda
From: "Armin Rigo" <[EMAIL PROTECTED]> > Hi Tim, > > > On Thu, Feb 17, 2005 at 01:44:11PM -0500, Tim Peters wrote: > > >256 ** struct.calcsize('P') > > > > Now if you'll just sign and fax a Zope contributor agreement, I'll > > upgrade ZODB to use this slick trick . > > I hereby donate this lin

[Python-Dev] Requesting that a class be a new-style class

2005-02-18 Thread Nick Coghlan
This is something I've typed way too many times: Py> class C(): File "", line 1 class C(): ^ SyntaxError: invalid syntax It's the asymmetry with functions that gets to me - defining a function with no arguments still requires parentheses in the definition statement, but defining

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> I'm very glad you introduced the optimization of building small > constant tuples at compile-time. IMO, that was a pure win. It's been out in the wild for a while now with no issues. I'm somewhat happy with it. > the transformation isn't semantically correct on the > face of it. Well that

[Python-Dev] Proposal for a module to deal with hashing

2005-02-18 Thread Nick Coghlan
Gregory P. Smith wrote: fyi - i've updated the python sha1/md5 openssl patch. it now replaces the entire sha and md5 modules with a generic hashes module that gives access to all of the hash algorithms supported by OpenSSL (including appropriate legacy interface wrappers and falling back to the ol

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Tim Peters
[Tim Peters] >> grow the list to its final size once, at the start (overestimating if >> you don't know for sure). Then instead of appending, keep an index to >> the next free slot, same as you'd do in C. Then the list guts never >> move, so if that doesn't yield the same kind of speedup without

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Tim Peters
[Raymond Hettinger] > ... > The problem with the transformation was that it didn't handle the case > where x was non-hashable and it would raise a TypeError instead of > returning False as it should. I'm very glad you introduced the optimization of building small constant tuples at compile-time.

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> >>Wouldn't it help a lot more if the compiler would detect that > >>(1,2,3) is immutable and convert it into a constant at > >>compile time ?! > > > > > > Yes. We've already gotten it to that point: . . . > > Cool. Does that work for all tuples in the program ? It is limited to just tuples of

Re: [Python-Dev] Re: Re: Re: Prospective Peephole Transformation

2005-02-18 Thread Tim Peters
[Phillip J. Eby] >> Still, it's rather interesting that tuple.__contains__ appears slower than a >> series of LOAD_CONST and "==" operations, considering that the tuple >> should be doing basically the same thing, only> without bytecode fetch-and- >> decode overhead. Maybe it's tuple.__contains__

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Evan Jones
On Feb 18, 2005, at 17:51, Tim Peters wrote: grow the list to its final size once, at the start (overestimating if you don't know for sure). Then instead of appending, keep an index to the next free slot, same as you'd do in C. Then the list guts never move, so if that doesn't yield the same kind

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Guido van Rossum
[Travis] > > then how about if arrayobjects can make it in the core, then a check for > > a rank-0 integer-type > > arrayobject is allowed before raising an exception? Sure, *if* you can get the premise accepted. [David] > Following up on Bob's point, maybe making rank-0 integer type > arrayobjec

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread M.-A. Lemburg
Raymond Hettinger wrote: Wouldn't it help a lot more if the compiler would detect that (1,2,3) is immutable and convert it into a constant at compile time ?! Yes. We've already gotten it to that point: Python 2.5a0 (#46, Feb 15 2005, 19:11:35) [MSC v.1200 32 bit (Intel)] on win32 import dis dis.d

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread David Ascher
On Fri, 18 Feb 2005 15:40:54 -0700, Travis Oliphant <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > >>Would it be possible to change > >> > >>_PyEval_SliceIndex in ceval.c > >> > >>so that rather than throwing an error if the indexing object is not an > >>integer, the code first checks t

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Tim Peters
[Tim Peters] ... >> Then you allocate a small object, marked 's': >> >> bbbsfff [Evan Jones] > Isn't the whole point of obmalloc No, because it doesn't matter what follows that introduction: obmalloc has several points, including exploiting the GIL, heuris

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Travis Oliphant
Guido van Rossum wrote: Would it be possible to change _PyEval_SliceIndex in ceval.c so that rather than throwing an error if the indexing object is not an integer, the code first checks to see if the object has a tp_as_number->nb_int method and calls it instead. I don't think this is the rig

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> Wouldn't it help a lot more if the compiler would detect that > (1,2,3) is immutable and convert it into a constant at > compile time ?! Yes. We've already gotten it to that point: Python 2.5a0 (#46, Feb 15 2005, 19:11:35) [MSC v.1200 32 bit (Intel)] on win32 >>> import dis >>> dis.dis(compile

Re: [Python-Dev] Memory Allocator Part 2: Did I get it right?

2005-02-18 Thread Evan Jones
Sorry for taking so long to get back to this thread, it has been one of those weeks for me. On Feb 16, 2005, at 2:50, Martin v. Löwis wrote: Evan then understood the feature, and made it possible. This is very true: it was a very useful exercise. I can personally accept breaking the code that sti

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Evan Jones
On Thu, 2005-02-17 at 22:38, Tim Peters wrote: Then you allocate a small object, marked 's': bbbsfff Isn't the whole point of obmalloc is that we don't want to allocate "s" on the heap, since it is small? I guess "s" could be an object that might potentiall

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Bob Ippolito
On Feb 18, 2005, at 4:36 PM, David Ascher wrote: On Fri, 18 Feb 2005 13:28:34 -0800, Guido van Rossum <[EMAIL PROTECTED]> wrote: Would it be possible to change _PyEval_SliceIndex in ceval.c so that rather than throwing an error if the indexing object is not an integer, the code first checks to se

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Guido van Rossum
[Travis] > > > Would it be possible to change > > > > > > _PyEval_SliceIndex in ceval.c > > > > > > so that rather than throwing an error if the indexing object is not an > > > integer, the code first checks to see if the object has a > > > tp_as_number->nb_int method and calls it instead. [Guido

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread David Ascher
On Fri, 18 Feb 2005 13:28:34 -0800, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > Would it be possible to change > > > > _PyEval_SliceIndex in ceval.c > > > > so that rather than throwing an error if the indexing object is not an > > integer, the code first checks to see if the object has a > >

[Python-Dev] Fix _PyEval_SliceIndex (Take two)

2005-02-18 Thread Travis Oliphant
(More readable second paragraph) Hello again, There is a great discussion going on the numpy list regarding a proposed PEP for multidimensional arrays that is in the works. During this discussion a problem has resurfaced regarding slicing with objects that are not IntegerType objects but that ha

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Brett C.
Travis Oliphant wrote: Hello again, There is a great discussion going on the numpy list regarding a proposed PEP for multidimensional arrays that is in the works. During this discussion as resurfaced regarding slicing with objects that are not IntegerType objects but that have a tp_as_number->nb

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Guido van Rossum
> Would it be possible to change > > _PyEval_SliceIndex in ceval.c > > so that rather than throwing an error if the indexing object is not an > integer, the code first checks to see if the object has a > tp_as_number->nb_int method and calls it instead. I don't think this is the right solution;

[Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Travis Oliphant
Hello again, There is a great discussion going on the numpy list regarding a proposed PEP for multidimensional arrays that is in the works. During this discussion as resurfaced regarding slicing with objects that are not IntegerType objects but that have a tp_as_number->nb_int method to convert

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread M.-A. Lemburg
Raymond Hettinger wrote: Based on some ideas from Skip, I had tried transforming the likes of "x in (1,2,3)" into "x in frozenset([1,2,3])". When applicable, it substantially simplified the generated code and converted the O(n) lookup into an O(1) step. There were substantial savings even if the

[Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Jim Jewett
Raymond Hettinger: > tried transforming the likes of "x in (1,2,3)" into "x in > frozenset([1,2,3])". >... There were substantial savings even if the set contained only a single entry. >... where x was non-hashable and it would raise a TypeError instead of > returning False as it should. I

[Python-Dev] Re: Re: Re: Prospective Peephole Transformation

2005-02-18 Thread Fredrik Lundh
Phillip J. Eby wrote: >>here's the disassembly: > > FYI, that's not a dissassembly of what timeit was actually timing; see > 'template' in timeit.py. > As a practical matter, the only difference would probably be the use of > LOAD_FAST instead of > LOAD_NAME, as > timeit runs the code in a fun

Re: [Python-Dev] Re: Re: Prospective Peephole Transformation

2005-02-18 Thread Phillip J. Eby
At 05:52 PM 2/18/05 +0100, Fredrik Lundh wrote: Phillip J. Eby wrote: > Were these timings done with the code that turns (1,2,3) into a constant? I used a stock 2.4 from python.org, which seems to do this (for tuples, not for lists). > Also, I presume that these timings still include extra LOAD_FAS

[Python-Dev] Re: Re: Prospective Peephole Transformation

2005-02-18 Thread Fredrik Lundh
Phillip J. Eby wrote: > Were these timings done with the code that turns (1,2,3) into a constant? I used a stock 2.4 from python.org, which seems to do this (for tuples, not for lists). > Also, I presume that these timings still include extra LOAD_FAST operations > that could be replaced > wit

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Phillip J. Eby
At 04:45 PM 2/18/05 +0100, Fredrik Lundh wrote: Phillip J. Eby wrote: >>Only contains expressions are translated: >> >> "if x in [1,2,3]" >> >>currently turns into: >> >> "if x in (1,2,3)" >> >>and I'm proposing that it go one step further: >> >> "if x in Seachset([1,2,3])" > > ISTM tha

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Skip Montanaro
>> > Raymond then >> translated >> > >> > for x in [1,2,3]: >> > >> > to >> > >> > for x in frozenset([1,2,3]): Raymond> That's not right. for-statements are not touched. Thanks for the correction. My apologies for the misstep. Skip

[Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Fredrik Lundh
Phillip J. Eby wrote: >>Only contains expressions are translated: >> >> "if x in [1,2,3]" >> >>currently turns into: >> >> "if x in (1,2,3)" >> >>and I'm proposing that it go one step further: >> >> "if x in Seachset([1,2,3])" > > ISTM that whenever I use a constant in-list like that,

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Phillip J. Eby
At 10:15 AM 2/18/05 -0500, Raymond Hettinger wrote: Only contains expressions are translated: "if x in [1,2,3]" currently turns into: "if x in (1,2,3)" and I'm proposing that it go one step further: "if x in Seachset([1,2,3])" ISTM that whenever I use a constant in-list like that, it's

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> > Raymond then > translated > > > > for x in [1,2,3]: > > > > to > > > > for x in frozenset([1,2,3]): That's not right. for-statements are not touched. > I may be missing something here (didn't follow the whole thread) but > those two are not functionally equal. > The docstring on fro

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Irmen de Jong
Skip Montanaro wrote: I suggested that since the standard library code is commonly used as an example of basic Python principles (that's probably not the right word), it should uphold that ideal tuple/list distinction. Raymond then translated for x in [1,2,3]: to for x in frozenset([1,2,3]

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> I'm unclear why the list in "for x in [1,2,3]" or "if x not in [1,2,3]" > can't fairly easily be recognized as a constant and just be placed in the > constants array. That part got done (at least for the if-statement). The question is whether the type transformation idea should be carried a st

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Skip Montanaro
>> Based on some ideas from Skip, I had tried transforming the likes of >> "x in (1,2,3)" into "x in frozenset([1,2,3])" Fredrik> savings in what? time or bytecode size? constructed Fredrik> micro-benchmarks, or examples from real-life code? Fredrik> do we have any stat

Re: [Python-Dev] Five review rule on the /dev/ page?

2005-02-18 Thread Skip Montanaro
aahz> This should go into Brett's survey of the Python dev process, not aahz> as official documentation. It's simply an offer made by some of aahz> the prominent members of python-dev. As long as it's referred to from www.python.org/dev that's fine. Skip ___

Re: [Python-Dev] builtin_id() returns negative numbers

2005-02-18 Thread Armin Rigo
Hi Tim, On Thu, Feb 17, 2005 at 01:44:11PM -0500, Tim Peters wrote: > >256 ** struct.calcsize('P') > > Now if you'll just sign and fax a Zope contributor agreement, I'll > upgrade ZODB to use this slick trick . I hereby donate this line of code to the public domain :-) Armin _

Re: [Python-Dev] license issues with profiler.py and md5.h/md5c.c

2005-02-18 Thread Martin v. Löwis
Donovan Baarda wrote: This patch keeps the current md5c.c, md5module.c files and adds the following; _hashopenssl.c, hashes.py, md5.py, sha.py. [...] If all we wanted to do was fix the md5 module If we want to fix the licensing issues with the md5 module, this patch does not help at all, as it keep

[Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Fredrik Lundh
Raymond Hettinger wrote: > Based on some ideas from Skip, I had tried transforming the likes of "x > in (1,2,3)" into "x in frozenset([1,2,3])". When applicable, it > substantially simplified the generated code and converted the O(n) > lookup into an O(1) step. There were substantial savings eve