backoff icon indicating copy to clipboard operation
backoff copied to clipboard

Fix `on_*` handler typing

Open cdce8p opened this issue 1 year ago • 1 comments

  • Allow passing coroutine functions to on_* handlers by also accepting Callable[[Details], Coroutine[Any, Any, None] for _Handler.
  • Make None explicit for on_success, on_backoff, on_giveup.
  • Better solution for TypedDict fallback. Some type checkers don't like passing the TypedDict arguments from a dynamic dict. Use __init_subclass__ instead to deal with **kwargs in the fallback case.
  • Expose Details from __init__ to simplify typing for end-users.

cdce8p avatar Aug 23 '22 20:08 cdce8p

@bgreen-litl Would you be able to take a quick look? This issue is preventing us from upgrading to v2.

cdce8p avatar Sep 04 '22 09:09 cdce8p

Thank you! This is merged.

For the time being I removed Details from the top level name space. I think you're right it is handy for end users, but I think there might be some other stuff in _typing which might be similarly so. I am thinking it might be better to expose a backoff.typing module which is specific to any type hint stuff. At any, I want to do a quick release (v2.2.0) and didn't want to think about that detail too hard this second.

bgreen-litl avatar Oct 05 '22 14:10 bgreen-litl