Skip to content

Commit

Permalink
[PR #8364/0e4a5c3c backport][3.10] Improve accuracy of subapp resourc…
Browse files Browse the repository at this point in the history
…e types (#8366)

**This is a backport of PR #8364 as merged into master
(0e4a5c3).**

Co-authored-by: Sam Bull <git@sambull.org>
  • Loading branch information
patchback[bot] and Dreamsorcerer authored Apr 20, 2024
1 parent 40b1b71 commit 9bd65fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/8364.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor improvements to static typing -- by :user:`Dreamsorcerer`.
9 changes: 5 additions & 4 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

_T = TypeVar("_T")
_U = TypeVar("_U")
_Resource = TypeVar("_Resource", bound=AbstractResource)


class Application(MutableMapping[Union[str, AppKey[Any]], Any]):
Expand Down Expand Up @@ -334,7 +335,7 @@ async def handler(app: "Application") -> None:
reg_handler("on_shutdown")
reg_handler("on_cleanup")

def add_subapp(self, prefix: str, subapp: "Application") -> AbstractResource:
def add_subapp(self, prefix: str, subapp: "Application") -> PrefixedSubAppResource:
if not isinstance(prefix, str):
raise TypeError("Prefix must be str")
prefix = prefix.rstrip("/")
Expand All @@ -344,8 +345,8 @@ def add_subapp(self, prefix: str, subapp: "Application") -> AbstractResource:
return self._add_subapp(factory, subapp)

def _add_subapp(
self, resource_factory: Callable[[], AbstractResource], subapp: "Application"
) -> AbstractResource:
self, resource_factory: Callable[[], _Resource], subapp: "Application"
) -> _Resource:
if self.frozen:
raise RuntimeError("Cannot add sub application to frozen application")
if subapp.frozen:
Expand All @@ -359,7 +360,7 @@ def _add_subapp(
subapp._set_loop(self._loop)
return resource

def add_domain(self, domain: str, subapp: "Application") -> AbstractResource:
def add_domain(self, domain: str, subapp: "Application") -> MatchedSubAppResource:
if not isinstance(domain, str):
raise TypeError("Domain must be str")
elif "*" in domain:
Expand Down

0 comments on commit 9bd65fa

Please sign in to comment.