Skip to content

Fix hasattr's exception problems #46449

Description

@benjaminp
BPO 2196
Nosy @brettcannon, @birkenfeld, @benjaminp
Files
  • hasattr_fixes.diff: Let's hasattr propagate exceptions (with tests)
  • hasattr_docs.diff: Documentation for hasattr and exceptions
  • hasattr_fixes-good-indentation.diff: Lets hasattr propagate exceptions (with tests and proper indentation)
  • hasattr_fixes2.diff: Anything which doesn't inherit Exception goes
  • hasattr_fixes2-real.diff: Real patch for hasattr_fixes2
  • 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:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-05-12.00:41:47.228>
    created_at = <Date 2008-02-26.22:51:54.721>
    labels = ['interpreter-core', 'type-bug', 'tests', 'docs']
    title = "Fix hasattr's exception problems"
    updated_at = <Date 2008-05-12.00:41:47.130>
    user = 'https://github.com/benjaminp'

    bugs.python.org fields:

    activity = <Date 2008-05-12.00:41:47.130>
    actor = 'benjamin.peterson'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-05-12.00:41:47.228>
    closer = 'benjamin.peterson'
    components = ['Documentation', 'Interpreter Core', 'Tests']
    creation = <Date 2008-02-26.22:51:54.721>
    creator = 'benjamin.peterson'
    dependencies = []
    files = ['9563', '9567', '9576', '9630', '9631']
    hgrepos = []
    issue_num = 2196
    keywords = ['patch']
    message_count = 12.0
    messages = ['63055', '63112', '63138', '63147', '63151', '63341', '63350', '63366', '63367', '63996', '63999', '66693']
    nosy_count = 4.0
    nosy_names = ['brett.cannon', 'georg.brandl', '_doublep', 'benjamin.peterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2196'
    versions = ['Python 2.6']

    Activity

    1. benjaminp commented on Feb 26, 2008

      @benjaminp
      ContributorAuthor

      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.

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      testsTests in the Lib/test dir
      type-bugAn unexpected behavior, bug, or error
      on Feb 26, 2008
    3. benjaminp commented on Feb 28, 2008

      @benjaminp
      ContributorAuthor

      Here's a documentation change that explains hasattr's exception issues
      top accompany my patch.

    4. birkenfeld commented on Feb 29, 2008

      @birkenfeld
      Member

      Please reformat your patch using tabs.

    5. benjaminp commented on Feb 29, 2008

      @benjaminp
      ContributorAuthor

      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?

    6. brettcannon commented on Feb 29, 2008

      @brettcannon
      Member

      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.

    7. benjaminp commented on Mar 6, 2008

      @benjaminp
      ContributorAuthor

      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.

    8. doublep commented on Mar 7, 2008

      doublepmannequin
      Mannequin

      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.

    9. benjaminp commented on Mar 7, 2008

      @benjaminp
      ContributorAuthor

      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.

    10. benjaminp commented on Mar 7, 2008

      @benjaminp
      ContributorAuthor

      That last patch is malformed.

    11. benjaminp commented on Mar 18, 2008

      @benjaminp
      ContributorAuthor

      Further comments?

    12. brettcannon commented on Mar 18, 2008

      @brettcannon
      Member

      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).

    13. benjaminp commented on May 12, 2008

      @benjaminp
      ContributorAuthor

      Done in r63119.

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    docsDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions