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

Unexpected errors in __iter__ are masked in "in" and the operator module #85001

Closed
serhiy-storchaka opened this issue May 30, 2020 · 6 comments
Closed
Labels
3.8 3.9 3.10 interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented May 30, 2020

BPO 40824
Nosy @ned-deily, @serhiy-storchaka, @miss-islington
PRs
  • bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. #20537
  • [3.9] bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537) #21043
  • [3.8] bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537) #21044
  • [3.7] bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537) #21045
  • [3.6] bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537) #21046
  • 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 = None
    closed_at = <Date 2020-06-22.09:35:14.853>
    created_at = <Date 2020-05-30.11:36:12.337>
    labels = ['interpreter-core', 'type-bug', '3.8', '3.9', '3.10']
    title = 'Unexpected errors in __iter__ are masked in "in" and the operator module'
    updated_at = <Date 2020-06-24.09:11:43.783>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-06-24.09:11:43.783>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-06-22.09:35:14.853>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2020-05-30.11:36:12.337>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40824
    keywords = ['patch']
    message_count = 6.0
    messages = ['370372', '372039', '372044', '372045', '372238', '372240']
    nosy_count = 3.0
    nosy_names = ['ned.deily', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['20537', '21043', '21044', '21045', '21046']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40824'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @serhiy-storchaka
    Copy link
    Member Author

    serhiy-storchaka commented May 30, 2020

    All errors raised in the __iter__ method are masked by the TypeError exception in the "in" operator and functions operator.contains(), operator.indexOf() and operator.countOf().

    >>> class BadIterable:
    ...     def __iter__(self):
    ...         1/0
    ... 
    >>> 
    >>> 1 in BadIterable()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: argument of type 'BadIterable' is not iterable

    It includes exceptions out of control of the programmer like MemoryError and KeyboardInterrupt. Converting them to TypeError can lead to weird errors or incorrect results.

    See also similar bpo-26407.

    @serhiy-storchaka serhiy-storchaka added 3.7 3.10 3.8 3.9 interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels May 30, 2020
    @serhiy-storchaka
    Copy link
    Member Author

    serhiy-storchaka commented Jun 22, 2020

    New changeset cafe1b6 by Serhiy Storchaka in branch 'master':
    bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537)
    cafe1b6

    @miss-islington
    Copy link
    Contributor

    miss-islington commented Jun 22, 2020

    New changeset 353c4ba by Miss Islington (bot) in branch '3.9':
    bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537)
    353c4ba

    @miss-islington
    Copy link
    Contributor

    miss-islington commented Jun 22, 2020

    New changeset b99824a by Miss Islington (bot) in branch '3.8':
    bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537)
    b99824a

    @ned-deily
    Copy link
    Member

    ned-deily commented Jun 24, 2020

    @serhiy, you have opened PRs for this for 3.7 and 3.6, both of which are now in the security-fix phase of their release cycles. It looks like this behavior has been around for a long time and does not appear to be a security issue. Unless there is some important reason why this behavior should be changed in a security fix release (for 3.6) or as a release critical fix for 3.7.8 final and unless another core developer reviews the changes, I do not think the PRs should be merged to 3.7 or 3.6.

    @serhiy-storchaka
    Copy link
    Member Author

    serhiy-storchaka commented Jun 24, 2020

    Sorry, I was not sure which versions are in security-fix phase now.

    @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.8 3.9 3.10 interpreter-core 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

    3 participants