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

StopIteration subclass suppressed by contextlib.contextmanager #88732

Closed
graingert mannequin opened this issue Jul 5, 2021 · 6 comments
Closed

StopIteration subclass suppressed by contextlib.contextmanager #88732

graingert mannequin opened this issue Jul 5, 2021 · 6 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Mannequin

graingert mannequin commented Jul 5, 2021

BPO 44566
Nosy @rhettinger, @ncoghlan, @ambv, @1st1, @graingert, @miss-islington
PRs
  • bpo-44566: resolve differences between asynccontextmanager and contextmanager #27024
  • [3.10] bpo-44566: resolve differences between asynccontextmanager and contextmanager (GH-27024) #27266
  • [3.9] bpo-44566: resolve differences between asynccontextmanager and contextmanager (GH-27024) #27269
  • 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 2021-07-20.19:13:37.099>
    created_at = <Date 2021-07-05.09:45:40.323>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'StopIteration subclass suppressed by contextlib.contextmanager'
    updated_at = <Date 2021-07-20.19:13:37.099>
    user = 'https://github.com/graingert'

    bugs.python.org fields:

    activity = <Date 2021-07-20.19:13:37.099>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-20.19:13:37.099>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2021-07-05.09:45:40.323>
    creator = 'graingert'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44566
    keywords = ['patch']
    message_count = 6.0
    messages = ['396979', '396983', '397892', '397902', '397903', '397904']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'ncoghlan', 'lukasz.langa', 'yselivanov', 'graingert', 'miss-islington']
    pr_nums = ['27024', '27266', '27269']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue44566'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @graingert
    Copy link
    Mannequin Author

    graingert mannequin commented Jul 5, 2021

    https://bugs.python.org/issue1462485

    import contextlib
    
    @contextlib.contextmanager
    def foo():
        yield
    
    class StartIrritation(StopIteration):
        pass
    
    
    with foo():
        raise StartIrritation

    @graingert graingert mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.10 only security fixes 3.11 only security fixes 3.9 only security fixes labels Jul 5, 2021
    @graingert
    Copy link
    Mannequin Author

    graingert mannequin commented Jul 5, 2021

    This is the output:

    Traceback (most recent call last):
      File "/home/graingert/projects/close.py", line 5, in foo
        yield
      File "/home/graingert/projects/close.py", line 12, in <module>
        raise StartIrritation
    __main__.StartIrritation
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/home/graingert/projects/close.py", line 11, in <module>
        with foo():
      File "/usr/lib/python3.10/contextlib.py", line 151, in __exit__
        self.gen.throw(type, value, traceback)
    RuntimeError: generator raised StopIteration
    

    Note that this was fixed in @contextlib.asynccontextmanager

    import asyncio
    import contextlib
    
    @contextlib.asynccontextmanager
    async def foo():
        yield
    
    class StartIrritation(StopIteration):
        pass
    
    
    async def amain():
        try:
            async with foo():
                raise StartIrritation
        except StartIrritation:
            print("good")
        except RuntimeError:
            print("bad")
    
    asyncio.run(amain())
    

    @rhettinger rhettinger added stdlib Python modules in the Lib dir and removed 3.7 (EOL) end of life 3.8 only security fixes labels Jul 5, 2021
    @rhettinger rhettinger changed the title StopIteration subclass raised in body of 'with' statement suppressed StopIteration subclass suppressed by contextlib.contextmanager Jul 5, 2021
    @rhettinger rhettinger added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir and removed 3.7 (EOL) end of life 3.8 only security fixes labels Jul 5, 2021
    @rhettinger rhettinger changed the title StopIteration subclass raised in body of 'with' statement suppressed StopIteration subclass suppressed by contextlib.contextmanager Jul 5, 2021
    @rhettinger rhettinger added the type-bug An unexpected behavior, bug, or error label Jul 5, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2021

    New changeset 7f1c330 by Thomas Grainger in branch 'main':
    bpo-44566: resolve differences between asynccontextmanager and contextmanager (bpo-27024)
    7f1c330

    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2021

    New changeset 68b4690 by Miss Islington (bot) in branch '3.10':
    bpo-44566: resolve differences between asynccontextmanager and contextmanager (GH-27024) (bpo-27266)
    68b4690

    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2021

    New changeset 1c5c9c8 by Łukasz Langa in branch '3.9':
    [3.9] bpo-44566: resolve differences between asynccontextmanager and contextmanager (GH-27024). (bpo-27269)
    1c5c9c8

    @ambv
    Copy link
    Contributor

    ambv commented Jul 20, 2021

    Thanks! ✨ 🍰 ✨

    @ambv ambv closed this as completed Jul 20, 2021
    @ambv ambv closed this as completed Jul 20, 2021
    @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.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants