From 0d34d1ccef657dbb564835d95cc87d2c5f26c2ea Mon Sep 17 00:00:00 2001 From: Zhiwei Date: Sun, 22 Dec 2024 04:35:15 -0500 Subject: [PATCH] Fix incompatible type annotation of `get` method in the `HTTPMethodView` class (#3016) * Remove incompatible type annotation of `get` method in the view class * Update sanic/views.py --------- Co-authored-by: Adam Hopkins --- sanic/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sanic/views.py b/sanic/views.py index bdd48dc4cc..3df123d07b 100644 --- a/sanic/views.py +++ b/sanic/views.py @@ -115,8 +115,6 @@ def get(self, request: Request): to `"/v"`. """ - get: Optional[Callable[..., Any]] - decorators: List[Callable[[Callable[..., Any]], Callable[..., Any]]] = [] def __init_subclass__( @@ -146,9 +144,11 @@ def __init_subclass__( def dispatch_request(self, request: Request, *args, **kwargs): """Dispatch request to appropriate handler method.""" - handler = getattr(self, request.method.lower(), None) - if not handler and request.method == "HEAD": - handler = self.get + method = request.method.lower() + handler = getattr(self, method, None) + + if not handler and method == "head": + handler = getattr(self, "get") if not handler: # The router will never allow us to get here, but this is # included as a fallback and for completeness.