Skip to content

Commit

Permalink
web: Type SUPPORTED_METHODS so it can be overridden.
Browse files Browse the repository at this point in the history
Its default type is `Tuple[str, str, str, str, str, str, str]`, which
can only be overridden by a tuple of the exact same length.  Which is
not terribly useful for its stated purpose.

Type it as a `Collection[str]`, which should support folks overriding
it as any number of reasonable things, as it is only used by way of
`if request.method not in self.SUPPORTED_METHODS`.
  • Loading branch information
alexmv committed Dec 8, 2023
1 parent b3f2a4b commit 3230e95
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tornado/test/httpclient_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def patch(self):


class AllMethodsHandler(RequestHandler):
SUPPORTED_METHODS = RequestHandler.SUPPORTED_METHODS + ("OTHER",) # type: ignore
SUPPORTED_METHODS = RequestHandler.SUPPORTED_METHODS + ("OTHER",)

def method(self):
assert self.request.method is not None
Expand Down
4 changes: 1 addition & 3 deletions tornado/test/web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2187,9 +2187,7 @@ def test_standard_methods(self):

class PatchMethodTest(SimpleHandlerTestCase):
class Handler(RequestHandler):
SUPPORTED_METHODS = RequestHandler.SUPPORTED_METHODS + ( # type: ignore
"OTHER",
)
SUPPORTED_METHODS = RequestHandler.SUPPORTED_METHODS + ("OTHER",)

def patch(self):
self.write("patch")
Expand Down
12 changes: 10 additions & 2 deletions tornado/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def main():
import typing

if typing.TYPE_CHECKING:
from typing import Set # noqa: F401
from typing import Collection, Set # noqa: F401


# The following types are accepted by RequestHandler.set_header
Expand Down Expand Up @@ -192,7 +192,15 @@ class RequestHandler(object):
"""

SUPPORTED_METHODS = ("GET", "HEAD", "POST", "DELETE", "PATCH", "PUT", "OPTIONS")
SUPPORTED_METHODS = (
"GET",
"HEAD",
"POST",
"DELETE",
"PATCH",
"PUT",
"OPTIONS",
) # type: Collection[str]

_template_loaders = {} # type: Dict[str, template.BaseLoader]
_template_loader_lock = threading.Lock()
Expand Down

0 comments on commit 3230e95

Please sign in to comment.