Skip to content

generator.close() never raises GeneratorExit #135110

@hyperkai

Description

@hyperkai

Bug report

Bug description:

The doc of generator.close() says as shown below:

Raises a GeneratorExit at the point where the generator function was paused.

But generator.close() never raises GeneratorExit as shown below:

def func():
    yield 'Hello'
    yield 'World'

v = func()

print(v.close()) # None
print(v.close()) # None
def func():
    yield 'Hello'
    yield 'World'

v = func()

print(next(v)) # Hello

print(v.close()) # None
print(v.close()) # None
def func():
    yield 'Hello'
    yield 'World'

v = func()

print(next(v)) # Hello
print(next(v)) # World

print(v.close()) # None
print(v.close()) # None
def func():
    yield 'Hello'
    yield 'World'

v = func()

print(v.close()) # None

print(next(v)) # StopIteration
def func():
    yield 'Hello'
    yield 'World'

v = func()

print(next(v)) # Hello

print(v.close()) # None

print(next(v)) # StopIteration

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasypendingThe issue will be closed if no feedback is provided

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions