Skip to content
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

[3.11] gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (GH-94050) #94460

Merged
merged 1 commit into from
Jun 30, 2022

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Jun 30, 2022

The inspect version was not working with unittest.mock.AsyncMock.

The fix introduces special-casing of AsyncMock in
inspect.iscoroutinefunction equivalent to the one
performed in asyncio.iscoroutinefunction.

Co-authored-by: Łukasz Langa lukasz@langa.pl
(cherry picked from commit 4261b6b)

Co-authored-by: Mehdi ABAAKOUK sileht@sileht.net

pythonGH-94050)

The inspect version was not working with unittest.mock.AsyncMock.

The fix introduces special-casing of AsyncMock in
`inspect.iscoroutinefunction` equivalent to the one
performed in `asyncio.iscoroutinefunction`.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 4261b6b)

Co-authored-by: Mehdi ABAAKOUK <sileht@sileht.net>
@miss-islington
Copy link
Contributor Author

Status check is done, and it's a success ✅ .

@miss-islington
Copy link
Contributor Author

Status check is done, and it's a success ✅ .

@ambv ambv merged commit 9ebec7d into python:3.11 Jun 30, 2022
@miss-islington miss-islington deleted the backport-4261b6b-3.11 branch June 30, 2022 18:05
@graingert
Copy link
Contributor

Isn't 3.11 and 3.10 in feature freeze? Cc @pablogsal

@pablogsal
Copy link
Member

Isn't 3.11 and 3.10 in feature freeze? Cc @pablogsal

This is a bugfix, isn't it? The bug being they is was incorrectly identifying AsyncMock as not a coroutine. If we were raising or doing something different then that would have been an incompatible change or a new feature, but the current behaviour is wrong.

Maybe I am missing something, thought.

@graingert
Copy link
Contributor

I read this as a feature change to allow duck typed Function-like objects to pass iscoroutinefunction/isgeneratorfunction/isasyncgeneratorfunction

@pablogsal
Copy link
Member

pablogsal commented Jul 3, 2022

All the descriptions of the issue and the tests are about AsyncMock and the way the original issue is written and the code is as if the current behaviour is a bug. Are you concerns around that this affects more than just AsyncMock?

@pablogsal
Copy link
Member

@ambv Thoughts?

@graingert
Copy link
Contributor

graingert commented Jul 3, 2022

Are you concerns around that this affects more than just AsyncMock?

Yeah this affects both more than AsyncMock and more than iscoroutinefunction

@graingert
Copy link
Contributor

Also the notes in the PR reflect the old approach and not the approach used in the code:

The fix introduces special-casing of AsyncMock in
inspect.iscoroutinefunction equivalent to the one
performed in asyncio.iscoroutinefunction.

@pablogsal
Copy link
Member

Hummm, @ambv I think this should then not have been backported. We should revert both backports

@cjw296
Copy link
Contributor

cjw296 commented Jul 3, 2022

I dunno, this feels like a bug that is being fixed.
@graingert - what situations are you concerned about where this wouldn't be a bug fix?

@ambv
Copy link
Contributor

ambv commented Jul 4, 2022

I agree with @cjw296 that this is a bug fix. Instead of hard-coding AsyncMock as a type in inspect, we use a more generic version, which catches AsyncMock fine. The duck type needs to be very thorough to pass the test. This method was introduced for Cython functions.

I agree that the description of the PR could better indicate what the change is vs what problem it fixes.

@pablogsal
Copy link
Member

we use a more generic version, which catches AsyncMock fine. The duck type needs to be very thorough to pass the test. This method was introduced for Cython functions.

Well, but wouldn't this affect other code that currently is behaving in a (arguably incorrect) given way? Technically that prevents the backport unless all possible affected code is surely doing it wrong.

@pablogsal
Copy link
Member

I agree that the description of the PR could better indicate what the change is vs what problem it fixes.

At the very least, lest improve the NEWS entry, please.

@cjw296
Copy link
Contributor

cjw296 commented Jul 4, 2022

Well, but wouldn't this affect other code that currently is behaving in a (arguably incorrect) given way?

If it's behaving in an incorrect way before this fix, isn't that just another indication this is a bugfix?

@pablogsal
Copy link
Member

If it's behaving in an incorrect way before this fix, isn't that just another indication this is a bugfix?

Yes, as long as every affected case is behaving incorrectly.

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.

7 participants