adriangb / xpresso

A composable Python ASGI web framework
https://xpresso-api.dev/
MIT License
178 stars 4 forks source link

feat: add App.dependency_overrides #54

Closed adriangb closed 2 years ago

adriangb commented 2 years ago

App.dependency_overrides can be used as a mapping or context manager that yields a mapping

This reduces a lot of boilerplate for users by wrapping their callable in Depends for them and shortening the function calls. It also acts as an ExitStack: users can assign overrides without increasing indentation and they all get unwound when the underlaying context manager exits.

adriangb commented 2 years ago

A good example of boilerplate reduction: https://github.com/adriangb/xpresso/pull/54/files#diff-9b5a1fd2a242de1f77eb978967d3f9ff0862f7e6c244fac473a43ceac6f5f808

codecov-commenter commented 2 years ago

Codecov Report

Merging #54 (8735159) into main (e389542) will increase coverage by 0.04%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #54      +/-   ##
==========================================
+ Coverage   97.46%   97.50%   +0.04%     
==========================================
  Files         181      183       +2     
  Lines        5711     5764      +53     
  Branches      674      681       +7     
==========================================
+ Hits         5566     5620      +54     
  Misses         98       98              
+ Partials       47       46       -1     
Impacted Files Coverage Δ
tests/test_application.py 100.00% <100.00%> (ø)
tests/test_dependency_overrides.py 100.00% <100.00%> (ø)
...st_docs/advanced/dependencies/test_tutorial_004.py 100.00% <100.00%> (ø)
...st_docs/tutorial/dependencies/test_tutorial_001.py 100.00% <100.00%> (ø)
...st_docs/tutorial/dependencies/test_tutorial_002.py 100.00% <100.00%> (ø)
...st_docs/tutorial/dependencies/test_tutorial_003.py 100.00% <100.00%> (ø)
...st_docs/tutorial/dependencies/test_tutorial_004.py 100.00% <100.00%> (ø)
...st_docs/tutorial/dependencies/test_tutorial_006.py 100.00% <100.00%> (ø)
tests/test_lifespans.py 100.00% <100.00%> (ø)
tests/test_routing/test_mounts.py 100.00% <100.00%> (ø)
... and 2 more