Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hasattr's exception problems #46449

Closed
benjaminp opened this issue Feb 26, 2008 · 12 comments
Closed

Fix hasattr's exception problems #46449

benjaminp opened this issue Feb 26, 2008 · 12 comments
Assignees
Labels
docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@benjaminp
Copy link
Contributor

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']

    @benjaminp
    Copy link
    Contributor Author

    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.

    @benjaminp benjaminp added interpreter-core (Objects, Python, Grammar, and Parser dirs) tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Feb 26, 2008
    @benjaminp
    Copy link
    Contributor Author

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

    @benjaminp benjaminp added the docs Documentation in the Doc dir label Feb 28, 2008
    @birkenfeld
    Copy link
    Member

    Please reformat your patch using tabs.

    @benjaminp
    Copy link
    Contributor Author

    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?

    @brettcannon
    Copy link
    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.

    @benjaminp
    Copy link
    Contributor Author

    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.

    @doublep
    Copy link
    Mannequin

    doublep mannequin commented Mar 7, 2008

    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.

    @benjaminp
    Copy link
    Contributor Author

    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.

    @benjaminp
    Copy link
    Contributor Author

    That last patch is malformed.

    @benjaminp
    Copy link
    Contributor Author

    Further comments?

    @brettcannon
    Copy link
    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).

    @benjaminp
    Copy link
    Contributor Author

    Done in r63119.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants