GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-72889: remove redundant `mock.Mock()._is_coroutine = False` workarounds by graingert · Pull Request #94926 · python/cpython Conversation
|
| self.loop._add_reader = mock.Mock() | ||
| self.loop._add_reader._is_coroutine = False |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
when asyncio.iscoroutinefunction was implemented as:
cpython/Lib/asyncio/coroutines.py
Lines 245 to 248 in 2f84144
| def iscoroutinefunction(func): | |
| """Return True if func is a decorated coroutine function.""" | |
| return (getattr(func, '_is_coroutine', False) or | |
| _inspect_iscoroutinefunction(func)) |
this meant
self.loop._add_reader = mock.Mock() assert asyncio.iscoroutinefunction(self.loop._add_reader) is True # mock objects have a truthy _is_coroutine attribute! self.loop._add_reader._is_coroutine = False assert asyncio.iscoroutinefunction(self.loop._add_reader) is False # patching it works around the issue
however the implementation was changed to use a marker object:
cpython/Lib/asyncio/coroutines.py
Lines 16 to 23 in ec4745b
| # A marker for iscoroutinefunction. | |
| _is_coroutine = object() | |
| def iscoroutinefunction(func): | |
| """Return True if func is a decorated coroutine function.""" | |
| return (inspect.iscoroutinefunction(func) or | |
| getattr(func, '_is_coroutine', None) is _is_coroutine) |
and so now the _is_coroutine = False work-around is redundant:
self.loop._add_reader = mock.Mock() assert asyncio.iscoroutinefunction(self.loop._add_reader) is False # mock objects have an _is_coroutine but it's not the asyncio.coroutines._is_coroutine sentinel self.loop._add_reader._is_coroutine = False assert asyncio.iscoroutinefunction(self.loop._add_reader) is False # it's still False so the workaround is redundant
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't think this needs a news entry |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since this just changes tests and the tests pass, I think this is okay.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @graingert for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-94934 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…rkarounds (pythonGH-94926) (cherry picked from commit 07aeb74) Co-authored-by: Thomas Grainger <[email protected]>
…nds (GH-94926) (cherry picked from commit 07aeb74) Co-authored-by: Thomas Grainger <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.