Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Guido van Rossum
On 8/24/05, James Y Knight <[EMAIL PROTECTED]> wrote: > On Aug 24, 2005, at 9:39 PM, Brett Cannon wrote: > > On 8/24/05, Guido van Rossum <[EMAIL PROTECTED]> wrote: > >> On 8/24/05, James Y Knight <[EMAIL PROTECTED]> wrote: > >>> I think it must be the case that raising an object which does not > >

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread James Y Knight
On Aug 24, 2005, at 9:39 PM, Brett Cannon wrote: > On 8/24/05, Guido van Rossum <[EMAIL PROTECTED]> wrote: >> On 8/24/05, James Y Knight <[EMAIL PROTECTED]> wrote: >>> I think it must be the case that raising an object which does not >>> derive from an exception class must be deprecated as well in

Re: [Python-Dev] New mailbox module

2005-08-24 Thread Barry Warsaw
On Wed, 2005-08-24 at 22:33, A.M. Kuchling wrote: > So, it's time to start considering it for inclusion in the standard > library. This is a big change to a non-obscure module, so don't feel > able to make this decision on my own. > > I believe the code quality is acceptable, but would appreciat

[Python-Dev] New mailbox module

2005-08-24 Thread A.M. Kuchling
Gregory K. Johnson, who's been working on the mailbox module in nondist/sandbox/mailbox for Google's Summer of Code, thinks his project is essentially complete. He's added the ability to modifying mailboxes by adding and removing messages, adding test cases for the new features, and written the co

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Guido van Rossum
On 8/24/05, Brett Cannon <[EMAIL PROTECTED]> wrote: > Is there any desire for a __future__ statement that makes it a syntax > error? How about making 'raise' statements only work with objects > that inherit from BaseException? I doubt it. Few people are going to put a __future__ statement in to m

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Brett Cannon
On 8/24/05, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 8/24/05, Michael Chermside <[EMAIL PROTECTED]> wrote: > > Explicit is better than Implicit. I think that in newly written code > > "except Exception:" is better (more explicit and easier to understand) > > than "except:" Legacy code that

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Brett Cannon
On 8/24/05, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 8/24/05, James Y Knight <[EMAIL PROTECTED]> wrote: > > I think it must be the case that raising an object which does not > > derive from an exception class must be deprecated as well in order > > for "except:" to be deprecated. Otherwise,

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Guido van Rossum
On 8/24/05, Michael Hudson <[EMAIL PROTECTED]> wrote: > I really hope string exceptions can be killed off before 3.0. They > should be fully deprecated in 2.5. But what about class exceptions that don't inherit from Exception? That will take a while before we can deprecate that. Anyway, there ha

Re: [Python-Dev] Docs/Pointer to Tools/scripts?

2005-08-24 Thread Martin v. Löwis
Reinhold Birkenfeld wrote: > after adding Oleg Broytmann's findnocoding.py to Tools/scripts, I > wonder whether the Tools directory is documented at all. There are > many useful scripts there which many people will not find if they are > not listed anywhere in the docs. Christos already mentioned

Re: [Python-Dev] [Argon] Re: 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
Am 24.08.2005 um 20:20 schrieb Greg Wilson: >>> Walter Dörwald wrote: >>> At least it would remove the quadratic number of calls to _PyUnicodeUCS2_IsLinebreak(). For each character it would be called only once. > >> Martin v. Löwis wrote: >> >>> Correct. However, I very much

Re: [Python-Dev] Docs/Pointer to Tools/scripts?

2005-08-24 Thread Christos Georgiou
"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > after adding Oleg Broytmann's findnocoding.py to Tools/scripts, I wonder > whether the Tools directory is documented at all. There are many useful > scripts there which many people will not find if they are

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
Am 24.08.2005 um 21:15 schrieb Martin v. Löwis: > Walter Dörwald wrote: > > >>> Right. Not sure what people think whether this should still be >>> supported, but I keep supporting it whenever I think of it. >>> >> >> OK, so should we add this for 2.4.2 or only for 2.5? >> > > You mean, string.unic

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Michael Hudson
"Raymond Hettinger" <[EMAIL PROTECTED]> writes: >> > Hmm, that may not be a killer. I wonder if it is possible to treat >> > BaseException as a constant (like we do with None) and teach the >> > compiler to interpret it as catching anything that gets raised so > that >> > "except BaseException" w

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Raymond Hettinger
> > Hmm, that may not be a killer. I wonder if it is possible to treat > > BaseException as a constant (like we do with None) and teach the > > compiler to interpret it as catching anything that gets raised so that > > "except BaseException" will work like a bare except clause does now. > > Sorry

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Barry Warsaw
On Wed, 2005-08-24 at 15:15, Raymond Hettinger wrote: > Hmm, that may not be a killer. I wonder if it is possible to treat > BaseException as a constant (like we do with None) and teach the > compiler to interpret it as catching anything that gets raised so that > "except BaseException" will work

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Raymond Hettinger
[Guido van Rossum] > > OK, I'm convinced. Let's drop bare except for Python 3.0, and > > deprecate them until then, without changing the meaning. > > > > The deprecation message (to be generated by the compiler!) should > > steer people in the direction of specifying one particular exception > > (e

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Martin v. Löwis
Walter Dörwald wrote: >> Right. Not sure what people think whether this should still be >> supported, but I keep supporting it whenever I think of it. > > > OK, so should we add this for 2.4.2 or only for 2.5? You mean, string.unicodelinebreaks? I think something needs to be done to fix the perf

Re: [Python-Dev] Docs/Pointer to Tools/scripts?

2005-08-24 Thread Oleg Broytmann
Hello! On Wed, Aug 24, 2005 at 08:33:02PM +0200, Reinhold Birkenfeld wrote: > after adding Oleg Broytmann's findnocoding.py to Tools/scripts What's more, pysource.py is more than just a script - it's a generally useful module. Thank you for committing the code. Oleg. -- Oleg Broytma

[Python-Dev] Docs/Pointer to Tools/scripts?

2005-08-24 Thread Reinhold Birkenfeld
Hi, after adding Oleg Broytmann's findnocoding.py to Tools/scripts, I wonder whether the Tools directory is documented at all. There are many useful scripts there which many people will not find if they are not listed anywhere in the docs. Just a thought. Reinhold -- Mail address is perfectly

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Barry Warsaw
On Wed, 2005-08-24 at 12:38, "Martin v. Löwis" wrote: > I personally dislike recording the execution path in > local variables. This is like setting a flag in a loop > before the break, and testing the flag afterwards. > You can do this, but the else: clause of the loop is > just more readable. A

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
Martin v. Löwis wrote: > Walter Dörwald wrote: > >>At least it would remove the quadratic number of calls to >>_PyUnicodeUCS2_IsLinebreak(). For each character it would be called only >>once. > > Correct. However, I very much doubt that this is the cause of the > slowdown. Probably. We'd need a

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Martin v. Löwis
Walter Dörwald wrote: > At least it would remove the quadratic number of calls to > _PyUnicodeUCS2_IsLinebreak(). For each character it would be called only > once. Correct. However, I very much doubt that this is the cause of the slowdown. > The last part of the patch seems to be more related to

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
M.-A. Lemburg wrote: > Walter Dörwald wrote: > >>I wonder if we should switch back to a simple readline() implementation >>for those codecs that don't require the current implementation >>(basically every charmap codec). > > That would be my preference as well. The 2.4 .readline() approach >

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Donovan Baarda
On Wed, 2005-08-24 at 07:33, "Martin v. Löwis" wrote: > Walter Dörwald wrote: > > Martin v. Löwis wrote: > > > >> Walter Dörwald wrote: [...] > Actually, on a second thought - it would not remove the quadratic > aspect. You would still copy the rest string completely on each > split. So on the fir

Re: [Python-Dev] FW: Bare except clauses in PEP 348

2005-08-24 Thread Guido van Rossum
On 8/24/05, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > Hey guys, don't give up your bare except clauses so easily. They are an attractive nuisance by being so much shorter to type than the "right thing to do". Especially if they default to something whose use cases are rather esoteric (i.e. B

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Guido van Rossum
On 8/24/05, James Y Knight <[EMAIL PROTECTED]> wrote: > I think it must be the case that raising an object which does not > derive from an exception class must be deprecated as well in order > for "except:" to be deprecated. Otherwise, there is nothing you can > change "except:" to in order not to

Re: [Python-Dev] FW: Bare except clauses in PEP 348

2005-08-24 Thread Ron Adam
Raymond Hettinger wrote: > Hey guys, don't give up your bare except clauses so easily. Yes, Don't give up. I often write code starting with a bare except, then after it works, stick a raise in it to determine exactly what exception I'm catching. Then use that to rewrite a more explicit except

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
Martin v. Löwis wrote: > Walter Dörwald wrote: > >>Martin v. Löwis wrote: >> >>>Walter Dörwald wrote: >>> I think a maxsplit argument (just as for unicode.split()) would help too. >>> >>>Correct - that would allow to get rid of the quadratic part. >> >>OK, such a patch should be rather si

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Shane Hathaway
Niko Matsakis wrote: >> >> txn = new_transaction() >> try: >> txn.begin() >> rtn = do_work() >> finally: >> if exception_occurred(): >> txn.abort() >> else: >> txn.commit() >> return rtn >> > > Couldn't you just do: > > txn = new_transaction () > try

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Martin v. Löwis
Niko Matsakis wrote: > Couldn't you just do: > > txn = new_transaction () > try: > complete = 0 > txn.begin () > rtn = do_work () > complete = 1 > finally: > if not complete: txn.abort () > else: txn.commit () > > and then not need new builtins or anything fancy? I

Re: [Python-Dev] FW: Bare except clauses in PEP 348

2005-08-24 Thread Michael Chermside
Raymond writes: > Hey guys, don't give up your bare except clauses so easily. [...] Raymond: I agree that when comparing: // Code snippet A try: ... except SomeException: ... except BaseException: ... with // Code snippet B try: ... except

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Niko Matsakis
> > txn = new_transaction() > try: > txn.begin() > rtn = do_work() > finally: > if exception_occurred(): > txn.abort() > else: > txn.commit() > return rtn > Couldn't you just do: txn = new_transaction () try: complete = 0 txn.begin ()

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Shane Hathaway
Barry Warsaw wrote: > I agree about bare except, but there is a very valid use case for an > except clause that catches every possible exception. We need to make > sure we don't overlook this use case. As an example, say I'm building a > transaction-aware system, I'm going to want to write code l

[Python-Dev] FW: Bare except clauses in PEP 348

2005-08-24 Thread Raymond Hettinger
Hey guys, don't give up your bare except clauses so easily. They are useful. And, if given the natural meaning of "catch everything" and put in a natural position at the end of a suite, their meaning is plain and obvious. Remember beauty counts. I don't think there would be similar temptation t

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread James Y Knight
On Aug 24, 2005, at 11:10 AM, Guido van Rossum wrote: > On 8/24/05, Michael Chermside <[EMAIL PROTECTED]> wrote: > >> Explicit is better than Implicit. I think that in newly written code >> "except Exception:" is better (more explicit and easier to >> understand) >> than "except:" Legacy code t

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Guido van Rossum
On 8/24/05, Michael Chermside <[EMAIL PROTECTED]> wrote: > Explicit is better than Implicit. I think that in newly written code > "except Exception:" is better (more explicit and easier to understand) > than "except:" Legacy code that uses "except:" can remain unchanged *IF* > the meaning of "excep

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Barry Warsaw
On Wed, 2005-08-24 at 10:34, James Y Knight wrote: > I would rather see "except:" be deprecated eventually, and force the > user to say either except Exception, except BaseException, or even > better, except ActualExceptionIWantToCatch. I agree about bare except, but there is a very valid use

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread James Y Knight
On Aug 23, 2005, at 10:41 PM, Raymond Hettinger wrote: > [Guido van Rossum] > >> If we syntactically enforce that the bare except, if present, must be >> last, would that remove your objection? I agree that a bare except in >> the middle is an anomaly, but that doesn't mean we can't keep bare >>

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Martin v. Löwis
Walter Dörwald wrote: > Martin v. Löwis wrote: > >> Walter Dörwald wrote: >> >>> I think a maxsplit argument (just as for unicode.split()) would help >>> too. >> >> >> Correct - that would allow to get rid of the quadratic part. > > > OK, such a patch should be rather simple. I'll give it a try.

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
Martin v. Löwis wrote: > Walter Dörwald wrote: > >>I think a maxsplit argument (just as for unicode.split()) would help too. > > Correct - that would allow to get rid of the quadratic part. OK, such a patch should be rather simple. I'll give it a try. > We should also strive for avoiding the s

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Michael Chermside
Raymond Hettinger writes: > The latest version of PEP 348 still proposes that a bare except clause > will default to Exception instead of BaseException. Initially, I had > thought that might be a good idea but now think it is doomed and needs > to be removed from the PEP. Guido writes: > If we sy

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Martin v. Löwis
Walter Dörwald wrote: > I think a maxsplit argument (just as for unicode.split()) would help too. Correct - that would allow to get rid of the quadratic part. We should also strive for avoiding the second copy of the line, if the user requested keepends. I wonder whether it would be worthwhile to

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread M.-A. Lemburg
Martin v. Löwis wrote: > M.-A. Lemburg wrote: > >>I think it's worthwhile reconsidering this approach for >>character type queries that do no involve a huge number >>of code points. > > > I would advise against that. I measure both versions > (your version called PyUnicode_IsLinebreak2) with the

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
Martin v. Löwis wrote: > Walter Dörwald wrote: > >>This is caused by the chances to the codecs in 2.4. Basically the codecs >>no longer rely on C's readline() to do line splitting (which can't work >>for UTF-16), but do it themselves (via unicode.splitlines()). > > That explains why you get an

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Martin v. Löwis
M.-A. Lemburg wrote: > I think it's worthwhile reconsidering this approach for > character type queries that do no involve a huge number > of code points. I would advise against that. I measure both versions (your version called PyUnicode_IsLinebreak2) with the following code volatile int result;

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread M.-A. Lemburg
Walter Dörwald wrote: > I wonder if we should switch back to a simple readline() implementation > for those codecs that don't require the current implementation > (basically every charmap codec). That would be my preference as well. The 2.4 .readline() approach is really only needed for codecs

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Martin v. Löwis
Walter Dörwald wrote: > This is caused by the chances to the codecs in 2.4. Basically the codecs > no longer rely on C's readline() to do line splitting (which can't work > for UTF-16), but do it themselves (via unicode.splitlines()). That explains why you get any calls to IsLineBreak; it doesn'

Re: [Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)

2005-08-24 Thread Walter Dörwald
Keir Mierle wrote: > Hi, I'm working on Argon (http://www.third-bit.com/trac/argon) with Greg > Wilson this summer > > We're having a very strange problem with Python's unicode parsing of source > files. Basically, our CGI script was running extremely slowly on our > production > box (a pokey du

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Nick Coghlan
Raymond Hettinger wrote: > The latest version of PEP 348 still proposes that a bare except clause > will default to Exception instead of BaseException. Initially, I had > thought that might be a good idea but now think it is doomed and needs > to be removed from the PEP. One thing I assumed was t

Re: [Python-Dev] Bare except clauses in PEP 348

2005-08-24 Thread Niko Matsakis
> As for the rest, I'm not as sure and it would be helpful to get > thoughts > from others on this one. My sense is that blocking the clause from > appearing in the middle is treating the symptom and not the disease. +1 It would be better to prohibit bare except entirely (well, presumably at