Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix callable class generator dependencies#1365

Merged
tiangolo merged 2 commits into
fastapi:masterfrom
mrosales:fix-callable-class-dependencies
Jun 12, 2020
Merged

Fix callable class generator dependencies#1365
tiangolo merged 2 commits into
fastapi:masterfrom
mrosales:fix-callable-class-dependencies

Conversation

@mrosales

@mrosales mrosales commented May 2, 2020

Copy link
Copy Markdown
Contributor

Fixes/related to #1204

Resolving dependencies uses inspect.isgeneratorfunction and inspect.isasyncgenfunction which match async methods and functions, but not a class (or other callable) that has an async generator __call__ method.

It also adds 4 new test cases to ensure that dependencies work as expected for class methods that yield instead of return values.

@codecov

codecov Bot commented May 2, 2020

Copy link
Copy Markdown

Codecov Report

Merging #1365 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1365   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          226       226           
  Lines         6785      6822   +37     
=========================================
+ Hits          6785      6822   +37     
Impacted Files Coverage Δ
fastapi/dependencies/utils.py 100.00% <100.00%> (ø)
tests/test_dependency_class.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e77737...1edef0a. Read the comment docs.

@mrosales

mrosales commented May 2, 2020

Copy link
Copy Markdown
Contributor Author

Looks like using the asynccontextmanager decorator with a non function/method callable isn't supported on python3.6. I'll update the PR with a workaround.

@mrosales

mrosales commented May 8, 2020

Copy link
Copy Markdown
Contributor Author

@tiangolo this is ready to review if you'd like to take a look

@tiangolo tiangolo merged commit b90bf2d into fastapi:master Jun 12, 2020
@tiangolo

Copy link
Copy Markdown
Member

Excellent job @mrosales ! 🙇 🚀 🤓

Including all the investigation with the backport, very clever!

Thanks for your contribution! ☕ 🍰

@fanck0605

Copy link
Copy Markdown

@mrosales @tiangolo

Hello, may I ask if there are any specific considerations for replacing asyncio.iscoroutinefunction with inspect.iscoroutinefunction?

In Python version 3.9, this change will prevent asynchronous functions compiled with Cython from executing correctly, as inspect.iscoroutinefunction(cythonized_async_function) will return False. cython/cython#2273 (comment)

Is it possible to revert this method back to asyncio.iscoroutinefunction? If possible, I will submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants