Replies: 1 comment
-
I ended up using |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm writing some code that uses
on_predicate
to rate limit in an API client, roughly like this:This function will always return the return value of
fn()
, since it continues trying forever - but because I'm usingNone
as the sentinel object for the predicate, mypy wants the return type to beOptional[_T]
instead of_T
. I end up leaking implementation details to my callers, sinceNone
isn't ever returned to them, but the type system can't understand that.Are there patterns that people use to avoid this problem? I could write a wrapper function that casts away the optional, or I could raise an exception and use the
on_exception
handler instead, but I'm curious what others have done.Beta Was this translation helpful? Give feedback.
All reactions