Skip to content

Commit

Permalink
Fix incompatible type annotation of get method in the `HTTPMethodVi…
Browse files Browse the repository at this point in the history
…ew` class (#3016)

* Remove incompatible type annotation of `get` method in the view class

* Update sanic/views.py

---------

Co-authored-by: Adam Hopkins <[email protected]>
  • Loading branch information
ChihweiLHBird and ahopkins authored Dec 22, 2024
1 parent 1d8425b commit 0d34d1c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sanic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0d34d1c

Please sign in to comment.