From 27dfe44ec8cc9bf872d513bf76e4253cb1ab0a23 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:04:11 +0000 Subject: [PATCH] Replace AbstractMatchInfo with UrlMappingMatchInfo. (#6135) (#6137) * Replace AbstractMatchInfo with UrlMappingMatchInfo. * Create 4748.bugfix * Bump multidict from 5.1.0 to 5.2.0 (#96) Bumps [multidict](https://github.com/aio-libs/multidict) from 5.1.0 to 5.2.0. - [Release notes](https://github.com/aio-libs/multidict/releases) - [Changelog](https://github.com/aio-libs/multidict/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/multidict/compare/v5.1.0...v5.2.0) --- updated-dependencies: - dependency-name: multidict dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump sqren/backport-github-action from 1.0.40 to 1.0.41 (#99) Bumps [sqren/backport-github-action](https://github.com/sqren/backport-github-action) from 1.0.40 to 1.0.41. - [Release notes](https://github.com/sqren/backport-github-action/releases) - [Commits](https://github.com/sqren/backport-github-action/compare/v1.0.40...v1.0.41) --- updated-dependencies: - dependency-name: sqren/backport-github-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump coverage from 5.5 to 6.0.1 (#100) Bumps [coverage](https://github.com/nedbat/coveragepy) from 5.5 to 6.0.1. - [Release notes](https://github.com/nedbat/coveragepy/releases) - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst) - [Commits](https://github.com/nedbat/coveragepy/compare/coverage-5.5...6.0.1) --- updated-dependencies: - dependency-name: coverage dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump yarl from 1.6.3 to 1.7.0 (#101) Bumps [yarl](https://github.com/aio-libs/yarl) from 1.6.3 to 1.7.0. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.6.3...v1.7.0) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump multidict from 5.1.0 to 5.2.0 (#102) Bumps [multidict](https://github.com/aio-libs/multidict) from 5.1.0 to 5.2.0. - [Release notes](https://github.com/aio-libs/multidict/releases) - [Changelog](https://github.com/aio-libs/multidict/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/multidict/compare/v5.1.0...v5.2.0) --- updated-dependencies: - dependency-name: multidict dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump pytest-cov from 2.12.1 to 3.0.0 (#98) Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 2.12.1 to 3.0.0. - [Release notes](https://github.com/pytest-dev/pytest-cov/releases) - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v2.12.1...v3.0.0) --- updated-dependencies: - dependency-name: pytest-cov dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump flake8 from 3.9.2 to 4.0.0 (#103) Bumps [flake8](https://github.com/pycqa/flake8) from 3.9.2 to 4.0.0. - [Release notes](https://github.com/pycqa/flake8/releases) - [Commits](https://github.com/pycqa/flake8/compare/3.9.2...4.0.0) --- updated-dependencies: - dependency-name: flake8 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump coverage from 6.0.1 to 6.0.2 (#104) Bumps [coverage](https://github.com/nedbat/coveragepy) from 6.0.1 to 6.0.2. - [Release notes](https://github.com/nedbat/coveragepy/releases) - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst) - [Commits](https://github.com/nedbat/coveragepy/compare/6.0.1...6.0.2) --- updated-dependencies: - dependency-name: coverage dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump flake8 from 4.0.0 to 4.0.1 (#105) Bumps [flake8](https://github.com/pycqa/flake8) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/pycqa/flake8/releases) - [Commits](https://github.com/pycqa/flake8/compare/4.0.0...4.0.1) --- updated-dependencies: - dependency-name: flake8 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/checkout from 2.3.4 to 2.3.5 (#106) Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump frozenlist from 1.1.1 to 1.2.0 (#108) Bumps [frozenlist](https://github.com/aio-libs/frozenlist) from 1.1.1 to 1.2.0. - [Release notes](https://github.com/aio-libs/frozenlist/releases) - [Changelog](https://github.com/aio-libs/frozenlist/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/frozenlist/compare/v1.1.1...v1.2.0) --- updated-dependencies: - dependency-name: frozenlist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump frozenlist from 1.1.1 to 1.2.0 (#109) Bumps [frozenlist](https://github.com/aio-libs/frozenlist) from 1.1.1 to 1.2.0. - [Release notes](https://github.com/aio-libs/frozenlist/releases) - [Changelog](https://github.com/aio-libs/frozenlist/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/frozenlist/compare/v1.1.1...v1.2.0) --- updated-dependencies: - dependency-name: frozenlist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump aiosignal from 1.1.2 to 1.2.0 (#107) Bumps [aiosignal](https://github.com/aio-libs/aiosignal) from 1.1.2 to 1.2.0. - [Release notes](https://github.com/aio-libs/aiosignal/releases) - [Changelog](https://github.com/aio-libs/aiosignal/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiosignal/compare/v1.1.2...v1.2.0) --- updated-dependencies: - dependency-name: aiosignal dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump aiosignal from 1.1.2 to 1.2.0 (#110) Bumps [aiosignal](https://github.com/aio-libs/aiosignal) from 1.1.2 to 1.2.0. - [Release notes](https://github.com/aio-libs/aiosignal/releases) - [Changelog](https://github.com/aio-libs/aiosignal/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiosignal/compare/v1.1.2...v1.2.0) --- updated-dependencies: - dependency-name: aiosignal dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sam Bull Co-authored-by: Sam Bull Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> (cherry picked from commit 40646d078ca6f58eaf48805241ceef3a37a027cb) Co-authored-by: Andrew Svetlov --- CHANGES/4748.bugfix | 1 + aiohttp/web_app.py | 2 +- aiohttp/web_middlewares.py | 2 +- aiohttp/web_urldispatcher.py | 12 ++++++------ requirements/test.txt | 1 - 5 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 CHANGES/4748.bugfix diff --git a/CHANGES/4748.bugfix b/CHANGES/4748.bugfix new file mode 100644 index 00000000000..439a81e949e --- /dev/null +++ b/CHANGES/4748.bugfix @@ -0,0 +1 @@ +Change return type on URLDispatcher to UrlMappingMatchInfo to improve type annotations. diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index 77639dbe14f..c982f74eeb0 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -482,7 +482,7 @@ async def _handle(self, request: Request) -> StreamResponse: match_info.freeze() resp = None - request._match_info = match_info # type: ignore[assignment] + 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 a1acb303473..be3cff498b7 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[assignment] + 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 7e3771e4029..b76f2f3431b 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -85,7 +85,7 @@ _ExpectHandler = Callable[[Request], Awaitable[None]] -_Resolve = Tuple[Optional[AbstractMatchInfo], Set[str]] +_Resolve = Tuple[Optional["UrlMappingMatchInfo"], Set[str]] class _InfoDict(TypedDict, total=False): @@ -1000,7 +1000,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] @@ -1010,11 +1010,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) diff --git a/requirements/test.txt b/requirements/test.txt index ccdb1b8ff68..70efaabe694 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,4 +1,3 @@ - -r base.txt Brotli==1.0.9 coverage==6.0.2