Repository navigation
Fix hasattr's exception problems #46449
Description
Activity
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.- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Feb 26, 2008 Here's a documentation change that explains hasattr's exception issues
top accompany my patch.Please reformat your patch using tabs.
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?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.
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.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.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.That last patch is malformed.
Further comments?
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).
Done in r63119.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: