Closed
Description
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