Skip to content

Commit

Permalink
Improve accuracy of subapp resource types (#8364)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Apr 20, 2024
1 parent 9b6f2c0 commit 0e4a5c3
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 @@ -66,6 +66,7 @@

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


@final
Expand Down Expand Up @@ -270,7 +271,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 @@ -280,8 +281,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 @@ -293,7 +294,7 @@ def _add_subapp(
subapp.pre_freeze()
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 0e4a5c3

Please sign in to comment.