This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fix the docstring for AbstractEventLoopPolicy.get_event_loop
Type: Stage: resolved
Components: asyncio, Documentation Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Ido Michael, asvetlov, docs@python, drtyrsa, miss-islington, ned.deily, xtreak, yselivanov
Priority: normal Keywords: patch

Created on 2018-08-06 10:04 by drtyrsa, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16463 merged Ido Michael, 2019-09-28 14:42
PR 16568 merged miss-islington, 2019-10-03 21:09
PR 16569 merged miss-islington, 2019-10-03 21:09
Messages (10)
msg323190 - (view) Author: Vlad Starostin (drtyrsa) * Date: 2018-08-06 10:04
The docstring says "This may be None or an instance of EventLoop". But docs explicitly state that get_event_loop "must never return None". The same docstring is also in the example in docs: https://docs.python.org/3.6/library/asyncio-eventloops.html#customizing-the-event-loop-policy

I propose changing it to:

def get_event_loop(self):
    """Get the event loop.

    Returns an instance of EventLoop or raises an exception.
    """

If the wording is ok, I'll make a PR.
msg352131 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-09-12 11:39
Thanks for the report. This looks like a valid change to me as I can see from the docstring it says it can be None but in the source code there is an explicit check that if self._local._loop which is returned is None then raise a RuntimeError. I would propose removing the docstring in the example.


# Docstring says can be None

./python.exe -m pydoc asyncio.events.BaseDefaultEventLoopPolicy.get_event_loop | cat
Help on function get_event_loop in asyncio.events.BaseDefaultEventLoopPolicy:

asyncio.events.BaseDefaultEventLoopPolicy.get_event_loop = get_event_loop(self)
    Get the event loop.

    This may be None or an instance of EventLoop.


# RuntimeError is raised for None

./python.exe -m inspect asyncio.events:BaseDefaultEventLoopPolicy.get_event_loop
    def get_event_loop(self):
        """Get the event loop.

        This may be None or an instance of EventLoop.
        """
        if (self._local._loop is None and
                not self._local._set_called and
                isinstance(threading.current_thread(), threading._MainThread)):
            self.set_event_loop(self.new_event_loop())

        if self._local._loop is None:
            raise RuntimeError('There is no current event loop in thread %r.'
                               % threading.current_thread().name)

        return self._local._loop
msg352321 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-09-13 13:26
Vlad, the PR is very welcome!
msg353457 - (view) Author: Ido Michael (Ido Michael) * Date: 2019-09-28 14:43
I've fixed the documentation according to the thread.

Here's the PR: GH-16463

Ido
msg353878 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2019-10-03 21:08
New changeset b23a8423a923077e4f83d3f328bb7542b4c940ed by Yury Selivanov (idomic) in branch 'master':
bpo-34344 Fix AbstractEventLoopPolicy.get_event_loop docstring (GH-16463)
https://github.com/python/cpython/commit/b23a8423a923077e4f83d3f328bb7542b4c940ed
msg353880 - (view) Author: miss-islington (miss-islington) Date: 2019-10-03 21:27
New changeset 8edde5caabc611c6320fd104244abe3a409cf0b6 by Miss Islington (bot) in branch '3.8':
bpo-34344 Fix AbstractEventLoopPolicy.get_event_loop docstring (GH-16463)
https://github.com/python/cpython/commit/8edde5caabc611c6320fd104244abe3a409cf0b6
msg353881 - (view) Author: miss-islington (miss-islington) Date: 2019-10-03 21:27
New changeset 4de3fbe27f672dcd9c24d3e99258f39b12c365a5 by Miss Islington (bot) in branch '3.7':
bpo-34344 Fix AbstractEventLoopPolicy.get_event_loop docstring (GH-16463)
https://github.com/python/cpython/commit/4de3fbe27f672dcd9c24d3e99258f39b12c365a5
msg354691 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-10-15 07:30
New changeset 88204a3908663a574919f9c17278bcabed0598fa by Ned Deily (Miss Islington (bot)) in branch '3.7':
bpo-34344 Fix AbstractEventLoopPolicy.get_event_loop docstring (GH-16463)
https://github.com/python/cpython/commit/88204a3908663a574919f9c17278bcabed0598fa
msg357692 - (view) Author: Ido Michael (Ido Michael) * Date: 2019-12-01 20:07
@yselivanov

Can we close this?
msg357701 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-12-02 03:27
Closing this as fixed. Thanks.
History
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78525
2019-12-02 03:27:17xtreaksetstatus: open -> closed
resolution: fixed
messages: + msg357701

stage: patch review -> resolved
2019-12-01 20:07:51Ido Michaelsetmessages: + msg357692
2019-10-15 07:30:24ned.deilysetnosy: + ned.deily
messages: + msg354691
2019-10-03 21:27:38miss-islingtonsetmessages: + msg353881
2019-10-03 21:27:00miss-islingtonsetnosy: + miss-islington
messages: + msg353880
2019-10-03 21:09:10miss-islingtonsetpull_requests: + pull_request16160
2019-10-03 21:09:03miss-islingtonsetpull_requests: + pull_request16159
2019-10-03 21:08:34yselivanovsetmessages: + msg353878
2019-09-28 14:43:08Ido Michaelsetnosy: + Ido Michael
messages: + msg353457
2019-09-28 14:42:21Ido Michaelsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16048
2019-09-13 13:26:12asvetlovsetmessages: + msg352321
2019-09-12 11:39:32xtreaksetmessages: + msg352131
versions: + Python 3.9, - Python 3.6
2018-09-20 11:25:43xtreaksetnosy: + xtreak
2018-08-06 10:04:47drtyrsacreate