endpoints: Modify comments mentioning has_request_variables and REQ.

This commit is contained in:
Kenneth Rodrigues 2024-09-03 21:38:36 +05:30 committed by Tim Abbott
parent dc32396180
commit 1d580f143e
5 changed files with 14 additions and 15 deletions

View File

@ -79,7 +79,7 @@ class UnspecifiedValue:
We use this type as an explicit sentinel value for such endpoints. We use this type as an explicit sentinel value for such endpoints.
TODO: Can this be merged with the _NotSpecified class, which is TODO: Can this be merged with the _NotSpecified class, which is
currently an internal implementation detail of the REQ class? currently an internal implementation detail of the typed_endpoint?
""" """

View File

@ -1619,7 +1619,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
result = self.client_post(f"/json/bots/{self.get_bot_user(email).id}", bot_info) result = self.client_post(f"/json/bots/{self.get_bot_user(email).id}", bot_info)
# TODO: The "method" parameter is not currently tracked as a processed parameter # TODO: The "method" parameter is not currently tracked as a processed parameter
# by has_request_variables. Assert it is returned as an ignored parameter. # by typed_endpoint. Assert it is returned as an ignored parameter.
response_dict = self.assert_json_success(result, ignored_parameters=["method"]) response_dict = self.assert_json_success(result, ignored_parameters=["method"])
self.assertEqual("Fred", response_dict["full_name"]) self.assertEqual("Fred", response_dict["full_name"])

View File

@ -452,7 +452,7 @@ do not match the types declared in the implementation of {function.__name__}.\n"
method: str, method: str,
tags: set[str], tags: set[str],
) -> None: ) -> None:
# Our accounting logic in the `has_request_variables()` # Our accounting logic in the `typed_endpoint`
# code means we have the list of all arguments # code means we have the list of all arguments
# accepted by every view function in arguments_map. # accepted by every view function in arguments_map.
accepted_arguments = set(arguments_map[function_name]) accepted_arguments = set(arguments_map[function_name])
@ -477,7 +477,7 @@ so maybe we shouldn't include it in pending_endpoints.
try: try:
# Don't include OpenAPI parameters that live in # Don't include OpenAPI parameters that live in
# the path; these are not extracted by REQ. # the path; these are not extracted by typed_endpoint.
openapi_parameters = get_openapi_parameters( openapi_parameters = get_openapi_parameters(
url_pattern, method, include_url_parameters=False url_pattern, method, include_url_parameters=False
) )
@ -493,8 +493,7 @@ so maybe we shouldn't include it in pending_endpoints.
# some processing to match with OpenAPI rules # some processing to match with OpenAPI rules
# #
# * accepted_arguments is the full set of arguments # * accepted_arguments is the full set of arguments
# this method accepts (from the REQ declarations in # this method accepts.
# code).
# #
# * The documented parameters for the endpoint as recorded in our # * The documented parameters for the endpoint as recorded in our
# OpenAPI data in zerver/openapi/zulip.yaml. # OpenAPI data in zerver/openapi/zulip.yaml.
@ -527,12 +526,12 @@ so maybe we shouldn't include it in pending_endpoints.
def test_openapi_arguments(self) -> None: def test_openapi_arguments(self) -> None:
"""This end-to-end API documentation test compares the arguments """This end-to-end API documentation test compares the arguments
defined in the actual code using @has_request_variables and defined in the actual code using @typed_endpoint,
REQ(), with the arguments declared in our API documentation with the arguments declared in our API documentation
for every API endpoint in Zulip. for every API endpoint in Zulip.
First, we import the fancy-Django version of zproject/urls.py First, we import the fancy-Django version of zproject/urls.py
by doing this, each has_request_variables wrapper around each by doing this, each typed_endpoint wrapper around each
imported view function gets called to generate the wrapped imported view function gets called to generate the wrapped
view function and thus filling the global arguments_map variable. view function and thus filling the global arguments_map variable.
Basically, we're exploiting code execution during import. Basically, we're exploiting code execution during import.
@ -540,7 +539,7 @@ so maybe we shouldn't include it in pending_endpoints.
Then we need to import some view modules not already imported in Then we need to import some view modules not already imported in
urls.py. We use this different syntax because of the linters complaining urls.py. We use this different syntax because of the linters complaining
of an unused import (which is correct, but we do this for triggering the of an unused import (which is correct, but we do this for triggering the
has_request_variables decorator). typed_endpoint decorator).
At the end, we perform a reverse mapping test that verifies that At the end, we perform a reverse mapping test that verifies that
every URL pattern defined in the OpenAPI documentation actually exists every URL pattern defined in the OpenAPI documentation actually exists
@ -575,11 +574,11 @@ so maybe we shouldn't include it in pending_endpoints.
if function is get_events: if function is get_events:
# Work around the fact that the registered # Work around the fact that the registered
# get_events view function isn't where we do # get_events view function isn't where we do
# @has_request_variables. # @typed_endpoint.
# #
# TODO: Make this configurable via an optional argument # TODO: Make this configurable via an optional argument
# to has_request_variables, e.g. # to typed_endpoint, e.g.
# @has_request_variables(view_func_name="zerver.tornado.views.get_events") # @typed_endpoint(view_func_name="zerver.tornado.views.get_events")
function = get_events_backend function = get_events_backend
function_name = f"{function.__module__}.{function.__name__}" function_name = f"{function.__module__}.{function.__name__}"

View File

@ -338,7 +338,7 @@ def update_realm(
# #
# TODO: It should be possible to deduplicate this function up # TODO: It should be possible to deduplicate this function up
# further by some more advanced usage of the # further by some more advanced usage of the
# `REQ/has_request_variables` extraction. # `typed_endpoint` extraction.
req_vars = {} req_vars = {}
req_group_setting_vars = {} req_group_setting_vars = {}

View File

@ -168,7 +168,7 @@ def check_settings_values(
email_notifications_batching_period_seconds: int | None, email_notifications_batching_period_seconds: int | None,
default_language: str | None = None, default_language: str | None = None,
) -> None: ) -> None:
# We can't use REQ for this widget because # We can't use typed_endpoint for this widget because
# get_available_language_codes requires provisioning to be # get_available_language_codes requires provisioning to be
# complete. # complete.
if default_language is not None and default_language not in get_available_language_codes(): if default_language is not None and default_language not in get_available_language_codes():