Issue 2196: Fix hasattr's exception problems (original) (raw)

Issue2196

Created on 2008-02-26 22:51 by benjamin.peterson, last changed 2022-04-11 14:56 by admin. 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
2022-04-11 14:56:31 admin set github: 46449
2008-05-12 00:41:47 benjamin.peterson set status: open -> closedresolution: acceptedmessages: +
2008-03-25 20:32:11 benjamin.peterson set priority: normal
2008-03-18 21:51:53 brett.cannon set messages: +
2008-03-18 21:48:01 benjamin.peterson set messages: +
2008-03-07 21:34:04 benjamin.peterson set files: + hasattr_fixes2-real.diffmessages: +
2008-03-07 21:31:58 benjamin.peterson set files: + hasattr_fixes2.diffmessages: +
2008-03-07 11:10:12 _doublep set nosy: + _doublepmessages: +
2008-03-06 22:59:04 benjamin.peterson set assignee: georg.brandlmessages: +
2008-02-29 23:24:24 brett.cannon set nosy: + brett.cannonmessages: +
2008-02-29 22:04:35 benjamin.peterson set files: + hasattr_fixes-good-indentation.diffmessages: +
2008-02-29 14:11:38 georg.brandl set nosy: + georg.brandlmessages: +
2008-02-28 23🔞21 benjamin.peterson set files: + hasattr_docs.diffmessages: + components: + Documentation
2008-02-26 22:51:54 benjamin.peterson create