classification
Title: Fix hasattr's exception problems
Type: behavior Stage:
Components: Documentation, Interpreter Core, Tests Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: _doublep, benjamin.peterson, brett.cannon, georg.brandl
Priority: normal Keywords: patch

Created on 2008-02-26 22:51 by benjamin.peterson, last changed 2008-05-12 00:41 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
hasattr_fixes.diff benjamin.peterson, 2008-02-26 22:51 Let's hasattr propagate exceptions (with tests)
hasattr_docs.diff benjamin.peterson, 2008-02-28 23:18 Documentation for hasattr and exceptions
hasattr_fixes-good-indentation.diff benjamin.peterson, 2008-02-29 22:04 Lets hasattr propagate exceptions (with tests and proper indentation)
hasattr_fixes2.diff benjamin.peterson, 2008-03-07 21:31 Anything which doesn't inherit Exception goes
hasattr_fixes2-real.diff benjamin.peterson, 2008-03-07 21:34 Real patch for hasattr_fixes2
Messages (12)
msg63055 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-02-26 22:51
hasattr currently returns False when any exception happens in getattr. I
see that this tracker I previous patches trying to fix this issue, but
they were rejected because they only tried to catch attribute errors. My
patch only propagates SystemExit and KeyboardInterrupt exceptions.
msg63112 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-02-28 23:18
Here's a documentation change that explains hasattr's exception issues
top accompany my patch.
msg63138 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-02-29 14:11
Please reformat your patch using tabs.
msg63147 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-02-29 22:04
After looking more closely, I saw that this is documented at
http://www.python.org/dev/patches/style/. So the C uses tabs, and the
Python uses spaces?
msg63151 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-02-29 23:24
On Fri, Feb 29, 2008 at 2:04 PM, Benjamin Peterson
<report@bugs.python.org> wrote:
>
>  Benjamin Peterson added the comment:
>
>  After looking more closely, I saw that this is documented at
>  http://www.python.org/dev/patches/style/. So the C uses tabs, and the
>  Python uses spaces?

Yes, although that is changing in Python 3.0.
msg63341 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-03-06 22:59
I suppose another way we could do this is propagate any exception which
doesn't inherit Exception. I, however, like just having just those 2
specific exceptions continue.
msg63350 - (view) Author: Paul Pogonyshev (_doublep) Date: 2008-03-07 11:10
I think it would be better not to hardcode specific 2 exceptional cases
and indeed follow that second way of instanceof(..., Exception).  I
think it was introduced exactly to separate "things that can be caught
by default" from "things that may be caught only in very special cases".
 I don't find it good Python interpreter not following its own rules.
msg63366 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-03-07 21:31
Here's a patch for that. Personally, I'm +1 on either option; I just
want it fixed. :)
I suppose the only (minor) problem with propagate things which are not
Exception is libraries where the exceptions don't extend Exception.
However, the ability to do this is being removed in Py3k, so it's not huge.
msg63367 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-03-07 21:34
That last patch is malformed.
msg63996 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-03-18 21:48
Further comments?
msg63999 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-03-18 21:51
On Tue, Mar 18, 2008 at 4:48 PM, Benjamin Peterson
<report@bugs.python.org> wrote:
>
>  Benjamin Peterson <musiccomposition@gmail.com> added the comment:
>
>  Further comments?

I have not looked at the patch yet (and I don't know when I will get to it).
msg66693 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-12 00:41
Done in r63119.
History
Date User Action Args
2008-05-12 00:41:47benjamin.petersonsetstatus: open -> closed
resolution: accepted
messages: + msg66693
2008-03-25 20:32:11benjamin.petersonsetpriority: normal
2008-03-18 21:51:53brett.cannonsetmessages: + msg63999
2008-03-18 21:48:01benjamin.petersonsetmessages: + msg63996
2008-03-07 21:34:04benjamin.petersonsetfiles: + hasattr_fixes2-real.diff
messages: + msg63367
2008-03-07 21:31:58benjamin.petersonsetfiles: + hasattr_fixes2.diff
messages: + msg63366
2008-03-07 11:10:12_doublepsetnosy: + _doublep
messages: + msg63350
2008-03-06 22:59:04benjamin.petersonsetassignee: georg.brandl
messages: + msg63341
2008-02-29 23:24:24brett.cannonsetnosy: + brett.cannon
messages: + msg63151
2008-02-29 22:04:35benjamin.petersonsetfiles: + hasattr_fixes-good-indentation.diff
messages: + msg63147
2008-02-29 14:11:38georg.brandlsetnosy: + georg.brandl
messages: + msg63138
2008-02-28 23:18:21benjamin.petersonsetfiles: + hasattr_docs.diff
messages: + msg63112
components: + Documentation
2008-02-26 22:51:54benjamin.petersoncreate