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

dictitems_contains swallows compare errors #72376

Closed
zhangyangyu opened this issue Sep 17, 2016 · 4 comments
Closed

dictitems_contains swallows compare errors #72376

zhangyangyu opened this issue Sep 17, 2016 · 4 comments
Assignees
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@zhangyangyu
Copy link
Member

BPO 28189
Nosy @rhettinger, @vstinner, @serhiy-storchaka, @zhangyangyu
Files
  • dictitems_contains.patch
  • 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/rhettinger'
    closed_at = <Date 2016-09-19.04:50:13.484>
    created_at = <Date 2016-09-17.15:25:42.711>
    labels = ['interpreter-core', 'type-bug', '3.7']
    title = 'dictitems_contains swallows compare errors'
    updated_at = <Date 2016-09-19.04:51:41.385>
    user = 'https://github.com/zhangyangyu'

    bugs.python.org fields:

    activity = <Date 2016-09-19.04:51:41.385>
    actor = 'xiang.zhang'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2016-09-19.04:50:13.484>
    closer = 'rhettinger'
    components = ['Interpreter Core']
    creation = <Date 2016-09-17.15:25:42.711>
    creator = 'xiang.zhang'
    dependencies = []
    files = ['44717']
    hgrepos = []
    issue_num = 28189
    keywords = ['patch']
    message_count = 4.0
    messages = ['276801', '276940', '276941', '276942']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'vstinner', 'python-dev', 'serhiy.storchaka', 'xiang.zhang']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28189'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @zhangyangyu
    Copy link
    Member Author

    Now, when compare errors raised during in, dict.keys(), dict.values() and set all propagate the errors. But dict.items() will swallow the errors(only key compare):

    >>> class BadEq:
    ...     def __hash__(self):
    ...             return 7
    ...     def __eq__(self, other):
    ...             raise RuntimeError
    ... 
    >>> k1, k2, v1, v2 = BadEq(), BadEq(), BadEq(), BadEq()
    >>> d = {k1: v1}
    >>> k2 in d.keys()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 5, in __eq__
    RuntimeError
    >>> v2 in d.values()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 5, in __eq__
    RuntimeError
    >>> k2 in {k1}
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 5, in __eq__
    RuntimeError
    >>> (k2, v2) in d.items()
    False
    >>> (k2, v1) in d.items()
    False

    dictitems_contains.patch tries to fix this.

    @zhangyangyu zhangyangyu added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Sep 17, 2016
    @rhettinger rhettinger self-assigned this Sep 19, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 19, 2016

    New changeset 2a9e0e869ca7 by Raymond Hettinger in branch '3.5':
    Issue bpo-28189: dictitems_contains no longer swallows compare errors.
    https://hg.python.org/cpython/rev/2a9e0e869ca7

    @rhettinger
    Copy link
    Contributor

    Thanks for the patch.

    @zhangyangyu
    Copy link
    Member Author

    Thanks for the merge Raymond. :)

    @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
    3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants