New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type error when using contextlib.asynccontextmanager #193
Comments
@xueqiao001 thanks for taking the time to report this. When you declare: @asynccontextmanager
async def get_cm() -> AsyncGenerator[Foo, None]:
yield Foo() You're annotating that the resulting function after the
It is confusing, because this is legit: async def get_cm() -> AsyncGenerator[Foo, None]:
yield Foo()
By changing
This test goes green. I hope this helped. If I missed something, please re-open this issue. |
We may have to discuss whether keeping the existing behavior:
or changing it to be aligned with statically typed languages (e.g. Java):
|
So, here's the deal. Python behaves differently depending on which decorator it is. For the case I commented back in May, I thought I had the general case. I was wrong... Check this out:
So: 1 - For We'll have to investigate how to deal with this from TestSlide, @xueqiao001 sorry to guide towards the wrong direction back in May, tkz @fabriziocucci for reopening this. |
So, As far as I understand: @asynccontextmanager
async def get_cm() -> AsyncGenerator[int, None]:
yield 1
Doing what I suggested earlier: @asynccontextmanager
async def get_cm() -> AsyncContextManager:
yield 1 is technically the wrong annotation for IMHO, it seems that Opinions? PS: tkz @david-caro for finding the original Python bug https://bugs.python.org/issue8814 . |
Python Upstream bug filed: https://bugs.python.org/issue41231. |
I have 2 Python file foo.py and test_foo.py.
foo.py:
test_foo.py:
When I ran testslide test_foo.py. I hit this type error below.
The text was updated successfully, but these errors were encountered: