From ed0b3d337458d7161811547932b6476f2d4bc887 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 21 Dec 2019 07:24:08 +1000 Subject: [PATCH] add an example of how circular imports can be handled The type name needs to be quoted so it is evaluated after the module has been initialized. In the future when we drop support for python 3.6, and mypy is updated, we will be able to remove the quotes and use the following at the top of the file instead: from __future__ import annotations --- anki/cards.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/anki/cards.py b/anki/cards.py index 3198cc70c..dd29c769a 100644 --- a/anki/cards.py +++ b/anki/cards.py @@ -5,6 +5,7 @@ import pprint import time from typing import Any, Dict, Optional +import anki # pylint: disable=unused-import from anki.consts import * from anki.hooks import runHook from anki.notes import Note @@ -27,9 +28,8 @@ class Card: timerStarted: Optional[float] lastIvl: Optional[int] - def __init__(self, col, id: Optional[int] = None) -> None: - from anki.collection import _Collection - self.col: _Collection = col + def __init__(self, col: "anki.collection._Collection", id: Optional[int] = None) -> None: + self.col = col self.timerStarted = None self._qa = None self._note = None