Add type hints and keyword-only arguments for cache_memoize and friends.
Review Request #13987 — Created June 19, 2024 and submitted
cache_memoize()
andcache_memoize_iter()
didn't work well with type
hints before. Type checkers would infer a list of possible types, none
of which were likely to match the true type that would be returned, and
this forced all callers to eithercast()
or add atype: ignore
comment.These now infer the return types based on the callback function
provided. This helps ensure the right type in the majority of cases.
There's a caveat in that the actual cached data may always be of some
other type, but that's already something the caller was responsible for
handling.To keep things maintainable, these methods, along with
make_cache_key()
, now require keyword-only arguments for all optional
flags and settings. For a simple usage ofcache_memoize()
or
cache_memozie_iter()
, nothing changes, as thekey
and
lookup_callable
arguments can still be provided as positional
arguments, but all others are now optional.We're also taking the time to properly deprecate some old arguments,
which will be removed once keyword-only arguments become enforced.
Unit tests pass in Djblets and Review Board.
Summary | ID |
---|---|
ca32ee5f33e84f99df0b6b341593bb0af3195c2f |