This code leads to the error in the title:
def _cancel(tasks): {t.cancel() for t in tasks if not t.done()} return a