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
This commit is contained in:
Damien Elmes 2019-12-21 07:24:08 +10:00
parent 981b3f34a0
commit ed0b3d3374

View File

@ -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