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

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

Closed
youknowone opened this issue May 1, 2024 · 0 comments
Closed
Labels
type-bug An unexpected behavior, bug, or error

Comments

@youknowone
Copy link
Contributor

youknowone commented May 1, 2024

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

@youknowone youknowone added the type-bug An unexpected behavior, bug, or error label May 1, 2024
youknowone added a commit to youknowone/cpython that referenced this issue May 1, 2024
youknowone added a commit to youknowone/cpython that referenced this issue May 1, 2024
youknowone added a commit to youknowone/cpython that referenced this issue May 1, 2024
youknowone added a commit to youknowone/cpython that referenced this issue May 1, 2024
SonicField pushed a commit to SonicField/cpython that referenced this issue May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants