typing.Any vs object?

Yes, there is a difference. Although in Python 3, all objects are instances of object, including object itself, only Any documents that the return value should be disregarded by the typechecker. The Any type docstring states that object is a subclass of Any and vice-versa: >>> import typing >>> print(typing.Any.__doc__) Special type indicating an unconstrained … Read more

How to disable password request for a Jupyter notebook session?

The following is very unsafe, but you can remove the password completely with: jupyter notebook –ip=’*’ –NotebookApp.token=” –NotebookApp.password=” Without –NotebookApp.password=”, when connecting from a remote computer to a local Jupyter launched simply with: jupyter notebook –ip=’*’ it still asks for a password for security reasons, since users with access can run arbitrary Python code on … Read more

asyncio.ensure_future vs. BaseEventLoop.create_task vs. simple coroutine?

Actual info: Starting from Python 3.7 asyncio.create_task(coro) high-level function was added for this purpose. You should use it instead other ways of creating tasks from coroutimes. However if you need to create task from arbitrary awaitable, you should use asyncio.ensure_future(obj). Old info: ensure_future vs create_task ensure_future is a method to create Task from coroutine. It … Read more

How to use ‘yield’ inside async function?

Upd: Starting with Python 3.6 we have asynchronous generators and able to use yield directly inside coroutines. import asyncio async def async_generator(): for i in range(3): await asyncio.sleep(1) yield i*i async def main(): async for i in async_generator(): print(i) loop = asyncio.get_event_loop() try: loop.run_until_complete(main()) finally: loop.run_until_complete(loop.shutdown_asyncgens()) # see: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.shutdown_asyncgens loop.close() Old answer for Python 3.5: … Read more