Grant Jenks <grant.je...@gmail.com> added the comment:
This is not a bug in Python. The SyntaxError matches expected behavior. According to the Python grammar, you can't have "await" outside of a function. You have "await" at the globals scope which is not permitted. You may only "await" functions from within other functions. Doctest is designed to emulate what you would type into the Python shell. Your doctest snippet does not work there either: ``` $ python3 Python 3.7.0 (default, Jun 28 2018, 05:55:06) [Clang 9.1.0 (clang-902.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> async def hello_world(): ... return "Hello, world!" ... >>> await hello_world() File "<stdin>", line 1 SyntaxError: 'await' outside function ``` To make your doctests work, use ``asyncio.run`` like so: ``` import asyncio async def hello_world(): """ Will greet the world with a friendly hello. >>> asyncio.run(hello_world()) 'hello world' """ return "hello world" if __name__ == "__main__": import doctest doctest.testmod() ``` Stefan, you may get a quicker answer next time from a forum like StackOverflow. Yury, it's probably a good idea to cover this case in your upcoming asyncio docs improvements. ---------- nosy: +grantjenks _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34445> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com