Skip to content

Skip throw() when finalizing generators, if they do not include a try statement. #100977

Closed as not planned
@markshannon

Description

@markshannon

It would be easy enough to tag code objects that do not have explicit try statements.
We could skip the throw step when closing generators for such code objects.

Before "zero cost" exceptions, we checked the the block stack. If it was empty we would skip the throw step.
We could be something similar by checking the exception table, but the introduction of a generator wide implicit try-except to handle https://peps.python.org/pep-0479/ complicates this.

See #100762 for the genesis of this.
Generator expressions never have trys and tend to be short lived, so this would definitely help there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions