• 
      

    Add type hints and keyword-only arguments for cache_memoize and friends.

    Review Request #13987 — Created June 19, 2024 and submitted — Latest diff uploaded

    Information

    Djblets
    release-5.x

    Reviewers

    cache_memoize() and cache_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 either cast() or add a type: 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 of cache_memoize() or
    cache_memozie_iter(), nothing changes, as the key 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.

    Commits

    Files