Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace AbstractMatchInfo with UrlMappingMatchInfo. #5328

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Backport
uses: sqren/backport-github-action@v1.0.40
uses: sqren/backport-github-action@v1.0.41
with:
# Required
# Token to authenticate requests
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2.3.5
with:
submodules: true
- name: Setup Python 3.8
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2.3.5
with:
submodules: true
- name: Setup Python ${{ matrix.pyver }}
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
needs: pre-deploy
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2.3.5
with:
submodules: true
- name: Setup Python 3.8
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
needs: pre-deploy
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2.3.5
with:
submodules: true
- name: Set up QEMU
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
needs: pre-deploy
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2.3.5
with:
submodules: true
- name: Setup Python 3.8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
if: github.repository_owner == 'aiohttp'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2.3.5
- name: Set up Python
uses: actions/setup-python@v2
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGES/4748.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change return type on URLDispatcher to UrlMappingMatchInfo to improve type annotations.
2 changes: 1 addition & 1 deletion aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,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)
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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
Expand Down
12 changes: 6 additions & 6 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@


_ExpectHandler = Callable[[Request], Awaitable[None]]
_Resolve = Tuple[Optional[AbstractMatchInfo], Set[str]]
_Resolve = Tuple[Optional["UrlMappingMatchInfo"], Set[str]]


class _InfoDict(TypedDict, total=False):
Expand Down Expand Up @@ -982,7 +982,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]

Expand All @@ -992,11 +992,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:
Copy link
Member Author

@Dreamsorcerer Dreamsorcerer Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped the else here, as it is redundant, and makes it a little more difficult to see that the function will always return.
(The diff is a little awkward to look at, as it's split it weirdly, but all I've done is remove the else following the for).

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)
Expand Down
6 changes: 3 additions & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-r multidict.txt
# required c-ares will not build on windows and has build problems on Macos Python<3.7
aiodns==3.0.0; sys_platform=="linux" or sys_platform=="darwin" and python_version>="3.7"
aiosignal==1.1.2
aiosignal==1.2.0
async-timeout==4.0.0a3
asynctest==0.13.0; python_version<"3.8"
Brotli==1.0.9
cchardet==2.1.7
chardet==4.0.0
frozenlist==1.1.1
frozenlist==1.2.0
gunicorn==20.1.0
typing_extensions==3.7.4.3
uvloop==0.14.0; platform_system!="Windows" and implementation_name=="cpython" and python_version<"3.9" # MagicStack/uvloop#14
yarl==1.6.3
yarl==1.7.0
2 changes: 1 addition & 1 deletion requirements/cython.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
cython==0.29.24
# via -r requirements/cython.in
multidict==5.1.0
multidict==5.2.0
# via -r requirements/multidict.txt
typing_extensions==3.7.4.3
# via -r requirements/cython.in
20 changes: 10 additions & 10 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aiodns==3.0.0 ; sys_platform == "linux" or sys_platform == "darwin" and python_v
# via -r requirements/base.txt
aiohttp-theme==0.1.6
# via -r requirements/doc.txt
aiosignal==1.1.2
aiosignal==1.2.0
# via -r requirements/base.txt
alabaster==0.7.12
# via sphinx
Expand Down Expand Up @@ -61,7 +61,7 @@ click==7.1.2
# towncrier
click-default-group==1.2.2
# via towncrier
coverage==5.5
coverage[toml]==6.0.2
# via
# -r requirements/test.txt
# pytest-cov
Expand All @@ -79,15 +79,15 @@ filelock==3.0.12
# via
# -r requirements/lint.txt
# virtualenv
flake8==3.9.2
flake8==4.0.1
# via
# -r requirements/lint.txt
# flake8-pyi
flake8-pyi==20.10.0
# via -r requirements/lint.txt
freezegun==1.1.0
# via -r requirements/test.txt
frozenlist==1.1.1
frozenlist==1.2.0
# via
# -r requirements/base.txt
# aiosignal
Expand Down Expand Up @@ -128,7 +128,7 @@ mccabe==0.6.1
# via
# -r requirements/lint.txt
# flake8
multidict==5.1.0
multidict==5.2.0
# via
# -r requirements/multidict.txt
# yarl
Expand Down Expand Up @@ -169,13 +169,13 @@ py==1.10.0
# pytest
pycares==4.0.0
# via aiodns
pycodestyle==2.7.0
pycodestyle==2.8.0
# via
# -r requirements/lint.txt
# flake8
pycparser==2.20
# via cffi
pyflakes==2.3.0
pyflakes==2.4.0
# via
# -r requirements/lint.txt
# flake8
Expand All @@ -196,7 +196,7 @@ pytest==6.2.2
# -r requirements/test.txt
# pytest-cov
# pytest-mock
pytest-cov==2.12.1
pytest-cov==3.0.0
# via -r requirements/test.txt
pytest-mock==3.6.1
# via -r requirements/test.txt
Expand Down Expand Up @@ -257,12 +257,12 @@ toml==0.10.2
# mypy
# pre-commit
# pytest
# pytest-cov
# towncrier
tomli==1.2.1
# via
# -r requirements/lint.txt
# black
# coverage
towncrier==21.3.0
# via -r requirements/doc.txt
trustme==0.9.0 ; platform_machine != "i686"
Expand All @@ -287,7 +287,7 @@ virtualenv==20.4.2
# pre-commit
webcolors==1.11.1
# via blockdiag
yarl==1.6.3
yarl==1.7.0
# via -r requirements/base.txt

# The following packages are considered to be unsafe in a requirements file:
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
black==21.7b0; implementation_name=="cpython"
flake8==3.9.2
flake8==4.0.1
flake8-pyi==20.10.0
isort==5.9.3
mypy==0.910; implementation_name=="cpython"
Expand Down
6 changes: 3 additions & 3 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ distlib==0.3.1
# via virtualenv
filelock==3.0.12
# via virtualenv
flake8==3.9.2
flake8==4.0.1
# via
# -r requirements/lint.in
# flake8-pyi
Expand Down Expand Up @@ -54,9 +54,9 @@ pre-commit==2.15.0
# via -r requirements/lint.in
py==1.10.0
# via pytest
pycodestyle==2.7.0
pycodestyle==2.8.0
# via flake8
pyflakes==2.3.0
pyflakes==2.4.0
# via
# flake8
# flake8-pyi
Expand Down
2 changes: 1 addition & 1 deletion requirements/multidict.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
multidict==5.1.0
multidict==5.2.0
4 changes: 2 additions & 2 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

-r base.txt
Brotli==1.0.9
coverage==5.5
coverage==6.0.2
cryptography==3.3.1; platform_machine!="i686" and python_version<"3.9" # no 32-bit wheels; no python 3.9 wheels yet
freezegun==1.1.0
mypy==0.910; implementation_name=="cpython"
mypy-extensions==0.4.3; implementation_name=="cpython"
pytest==6.2.2
pytest-cov==2.12.1
pytest-cov==3.0.0
pytest-mock==3.6.1
re-assert==1.1.0
setuptools-git==1.2
Expand Down