mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
This makes `has_request_variables` more generic, in the sense of the return value, and also makes it more accurate, in the sense of requiring the first parameter of the decorated function to be `HttpRequest`, and preserving the function signature without using `cast`. This affects some callers of `has_request_variables` or the callers of its decoratedfunctions in the following manners: - Decorated non-view functions called directly in other functions cannot use `request` as a keyword argument. Becasue `Concatenate` turns the concatenated parameters (`request: HttpRequest` in this case) into positional-only parameters. Callers of `get_chart_data` are thus refactored. - Functions to be decorated that accept variadic keyword arguments must define `request: HttpRequest` as positional-only. Mypy in strict mode rejects such functions otherwise because it is possible for the caller to pass a keyword argument that has the same name as `request` for `**kwargs`. No defining `request: HttpRequest` as positional-only breaks type safety because function with positional-or-keyword parameters cannot be considered a subtype of a function with the same parameters in which some of them are positional-only. Consider `f(x: int, /, **kwargs: object) -> int` and `g(x: int, **kwargs: object) -> int`. `f(12, x="asd")` is valid but `g(12, x="asd")` is not. Signed-off-by: Zixuan James Li <p359101898@gmail.com>
17 KiB
17 KiB