Title: Fix the docstring for AbstractEventLoopPolicy.get_event_loop
Type: Stage:
Components: asyncio, Documentation Versions: Python 3.9, Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: asvetlov, docs@python, drtyrsa, xtreak, yselivanov
Priority: normal Keywords:

Created on 2018-08-06 10:04 by drtyrsa, last changed 2019-09-13 13:26 by asvetlov.

Messages (3)
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:

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 triager) 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 | cat
Help on function get_event_loop in = 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
    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)):

        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!
Date User Action Args
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