-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Taking advantage of adriangb/di@b0cd073 to make things a bit less verbose and error prone.
- Loading branch information
Showing
7 changed files
with
92 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "xpresso" | ||
version = "0.41.2" | ||
version = "0.42.0" | ||
description = "A developer centric, performant Python web framework" | ||
authors = ["Adrian Garcia Badaracco <[email protected]>"] | ||
readme = "README.md" | ||
|
@@ -36,7 +36,7 @@ classifiers = [ | |
|
||
[tool.poetry.dependencies] | ||
python = ">=3.7,<4" | ||
di = ">=0.69.0" | ||
di = ">=0.70.0" | ||
anyio = ">=3.4.0,<5" | ||
starlette = ">=0.17.1,<1" | ||
typing-extensions = { version = ">=3", python = "<3.9" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Any, Sequence | ||
|
||
from di.api.dependencies import DependantBase | ||
from di.api.scopes import Scope | ||
|
||
|
||
def endpoint_scope_resolver( | ||
dep: DependantBase[Any], | ||
sub_dependant_scopes: Sequence[Scope], | ||
_: Sequence[Scope], | ||
) -> Scope: | ||
"""Resolve scopes by defaulting to "connection" | ||
unless a sub-dependency has an "endpoint" scope | ||
in which case we drop down to that scope | ||
""" | ||
if dep.scope is not None: | ||
return dep.scope | ||
if "endpoint" in sub_dependant_scopes: | ||
return "endpoint" | ||
return "connection" | ||
|
||
|
||
def lifespan_scope_resolver( | ||
dep: DependantBase[Any], | ||
sub_dependant_scopes: Sequence[Scope], | ||
_: Sequence[Scope], | ||
) -> Scope: | ||
"""Always default to the "app" scope""" | ||
if dep.scope is None: | ||
return "app" | ||
return dep.scope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters