Skip to content

sys.set_asyncgen_hooks with invalid firstiter may partially set finalizer #118473

Closed
@youknowone

Description

@youknowone

Bug report

Bug description:

      finalizer = lambda *a: None
      try:
          sys.set_asyncgen_hooks(firstiter="invalid", finalizer=finalizer)
      except TypeError:  # TypeError due to invalid `firstiter` type
          cur = sys.get_asyncgen_hooks()
          self.assertIsNone(cur.firstiter)  # This is not set 
          self.assertIsNone(cur.finalizer)  # But this is set

PEP 525 doesn't imply or define partial initialization priority. Since inside of set_asyncgen_hooks is blackbox to user, this is surprising and users are hard to know they have to back up current setup and recover it when TypeError happens.

Inconsistency also cause user experience problem. Current order sys.set_asyncgen_hooks(firstiter="invalid", finalizer=finalizer) causes partial set, but sys.set_asyncgen_hooks(firstiter=finalizer, finalizer="invalid") will not.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions