“Fire and forget” python async/await

Upd: Replace asyncio.ensure_future with asyncio.create_task everywhere if you’re using Python >= 3.7 It’s a newer, nicer way to spawn tasks. asyncio.Task to “fire and forget” According to python docs for asyncio.Task it is possible to start some coroutine to execute “in the background”. The task created by asyncio.ensure_future won’t block the execution (therefore the function … Read more

What is the ‘@=’ symbol for in Python?

From the documentation: The @ (at) operator is intended to be used for matrix multiplication. No builtin Python types implement this operator. The @ operator was introduced in Python 3.5. @= is matrix multiplication followed by assignment, as you would expect. They map to __matmul__, __rmatmul__ or __imatmul__ similar to how + and += map … Read more

ImportError: No module named ‘django.core.urlresolvers’

Django 2.0 removes the django.core.urlresolvers module, which was moved to django.urls in version 1.10. You should change any import to use django.urls instead, like this: from django.urls import reverse Note that Django 2.0 removes some features that previously were in django.core.urlresolvers, so you might have to make some more changes before your code works. See … Read more

Python type hinting without cyclic imports

There isn’t a hugely elegant way to handle import cycles in general, I’m afraid. Your choices are to either redesign your code to remove the cyclic dependency, or if it isn’t feasible, do something like this: # some_file.py from typing import TYPE_CHECKING if TYPE_CHECKING: from main import Main class MyObject(object): def func2(self, some_param: ‘Main’): … … Read more