diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index d716ad31243..17a72f339d9 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -334,7 +334,7 @@ async def _handle(self, request: Request) -> StreamResponse: match_info.freeze() resp = None - request._match_info = match_info # type: ignore + request._match_info = match_info expect = request.headers.get(hdrs.EXPECT) if expect: resp = await match_info.expect_handler(request) diff --git a/aiohttp/web_middlewares.py b/aiohttp/web_middlewares.py index b122bd14fe5..df2ee57dca0 100644 --- a/aiohttp/web_middlewares.py +++ b/aiohttp/web_middlewares.py @@ -22,7 +22,7 @@ async def _check_request_resolves(request: Request, path: str) -> Tuple[bool, Re alt_request = request.clone(rel_url=path) match_info = await request.app.router.resolve(alt_request) - alt_request._match_info = match_info # type: ignore + alt_request._match_info = match_info if match_info.http_exception is None: return True, alt_request diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index 590b376afec..32d5e4378b5 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -79,7 +79,7 @@ _WebHandler = Callable[[Request], Awaitable[StreamResponse]] _ExpectHandler = Callable[[Request], Awaitable[None]] -_Resolve = Tuple[Optional[AbstractMatchInfo], Set[str]] +_Resolve = Tuple[Optional["UrlMappingMatchInfo"], Set[str]] class _InfoDict(TypedDict, total=False): @@ -977,7 +977,7 @@ def __init__(self) -> None: self._resources = [] # type: List[AbstractResource] self._named_resources = {} # type: Dict[str, AbstractResource] - async def resolve(self, request: Request) -> AbstractMatchInfo: + async def resolve(self, request: Request) -> UrlMappingMatchInfo: method = request.method allowed_methods = set() # type: Set[str] @@ -987,11 +987,11 @@ async def resolve(self, request: Request) -> AbstractMatchInfo: return match_dict else: allowed_methods |= allowed + + if allowed_methods: + return MatchInfoError(HTTPMethodNotAllowed(method, allowed_methods)) else: - if allowed_methods: - return MatchInfoError(HTTPMethodNotAllowed(method, allowed_methods)) - else: - return MatchInfoError(HTTPNotFound()) + return MatchInfoError(HTTPNotFound()) def __iter__(self) -> Iterator[str]: return iter(self._named_resources)