mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
move types.py into the files responsible for each type
This commit is contained in:
parent
06833f7301
commit
d3cc63efb0
9 changed files with 37 additions and 49 deletions
|
@ -25,14 +25,13 @@ from anki.errors import AnkiError
|
|||
from anki.hooks import runFilter
|
||||
from anki.lang import _, ngettext
|
||||
from anki.media import MediaManager
|
||||
from anki.models import ModelManager
|
||||
from anki.models import ModelManager, NoteType, Template
|
||||
from anki.notes import Note
|
||||
from anki.rsbackend import RustBackend
|
||||
from anki.sched import Scheduler as V1Scheduler
|
||||
from anki.schedv2 import Scheduler as V2Scheduler
|
||||
from anki.tags import TagManager
|
||||
from anki.template import TemplateRenderContext, render_card
|
||||
from anki.types import NoteType, QAData, Template
|
||||
from anki.template import QAData, TemplateRenderContext, render_card
|
||||
from anki.utils import (
|
||||
devMode,
|
||||
fieldChecksum,
|
||||
|
|
|
@ -12,8 +12,8 @@ from typing import Any, Optional, Tuple
|
|||
import anki
|
||||
from anki import hooks
|
||||
from anki.lang import _
|
||||
from anki.models import NoteType
|
||||
from anki.template import TemplateRenderContext
|
||||
from anki.types import NoteType
|
||||
from anki.utils import call, checksum, isMac, namedtmp, stripHTML, tmpdir
|
||||
|
||||
pngCommands = [
|
||||
|
|
|
@ -13,9 +13,17 @@ import anki # pylint: disable=unused-import
|
|||
from anki import hooks
|
||||
from anki.consts import *
|
||||
from anki.lang import _
|
||||
from anki.types import Field, NoteType, Template
|
||||
from anki.utils import checksum, ids2str, intTime, joinFields, splitFields
|
||||
|
||||
# types
|
||||
NoteType = Dict[str, Any]
|
||||
Field = Dict[str, Any]
|
||||
Template = Dict[str, Union[str, int, None]]
|
||||
TemplateRequirementType = str # Union["all", "any", "none"]
|
||||
# template ordinal, type, list of field ordinals
|
||||
TemplateRequiredFieldOrds = Tuple[int, TemplateRequirementType, List[int]]
|
||||
AllTemplateReqs = List[TemplateRequiredFieldOrds]
|
||||
|
||||
# Models
|
||||
##########################################################################
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from __future__ import annotations
|
|||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
import anki # pylint: disable=unused-import
|
||||
from anki.types import NoteType
|
||||
from anki.models import NoteType
|
||||
from anki.utils import (
|
||||
fieldChecksum,
|
||||
guid64,
|
||||
|
|
|
@ -8,8 +8,7 @@ import ankirspy # pytype: disable=import-error
|
|||
|
||||
import anki.backend_pb2 as pb
|
||||
import anki.buildinfo
|
||||
|
||||
from .types import AllTemplateReqs
|
||||
from anki.models import AllTemplateReqs
|
||||
|
||||
assert ankirspy.buildhash() == anki.buildinfo.buildhash
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any, Callable, List, Tuple, Union
|
|||
|
||||
from anki.consts import MODEL_CLOZE
|
||||
from anki.lang import _
|
||||
from anki.types import NoteType
|
||||
from anki.models import NoteType
|
||||
|
||||
models: List[Tuple[Union[Callable[[], str], str], Callable[[Any], NoteType]]] = []
|
||||
|
||||
|
|
|
@ -33,9 +33,29 @@ from typing import Any, Dict, List, Optional, Tuple
|
|||
|
||||
import anki
|
||||
from anki import hooks
|
||||
from anki.models import NoteType
|
||||
from anki.rsbackend import TemplateReplacementList
|
||||
from anki.sound import stripSounds
|
||||
from anki.types import NoteType, QAData
|
||||
|
||||
QAData = Tuple[
|
||||
# Card ID this QA comes from. Corresponds to 'cid' column.
|
||||
int,
|
||||
# Note ID this QA comes from. Corresponds to 'nid' column.
|
||||
int,
|
||||
# ID of the model (i.e., NoteType) for this QA's note. Corresponds to 'mid' column.
|
||||
int,
|
||||
# Deck ID. Corresponds to 'did' column.
|
||||
int,
|
||||
# Index of the card template (within the NoteType) this QA was built
|
||||
# from. Corresponds to 'ord' column.
|
||||
int,
|
||||
# Tags, separated by space. Corresponds to 'tags' column.
|
||||
str,
|
||||
# Corresponds to 'flds' column. TODO: document.
|
||||
str,
|
||||
# Corresponds to 'cardFlags' column. TODO: document
|
||||
int,
|
||||
]
|
||||
|
||||
|
||||
class TemplateRenderContext:
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
from typing import Any, Dict, List, Tuple, Union
|
||||
|
||||
# Model attributes are stored in a dict keyed by strings. This type alias
|
||||
# provides more descriptive function signatures than just 'Dict[str, Any]'
|
||||
# for methods that operate on models.
|
||||
# TODO: Use https://www.python.org/dev/peps/pep-0589/ when available in
|
||||
# supported Python versions.
|
||||
|
||||
NoteType = Dict[str, Any]
|
||||
|
||||
Field = Dict[str, Any]
|
||||
|
||||
Template = Dict[str, Union[str, int, None]]
|
||||
|
||||
QAData = Tuple[
|
||||
# Card ID this QA comes from. Corresponds to 'cid' column.
|
||||
int,
|
||||
# Note ID this QA comes from. Corresponds to 'nid' column.
|
||||
int,
|
||||
# ID of the model (i.e., NoteType) for this QA's note. Corresponds to 'mid' column.
|
||||
int,
|
||||
# Deck ID. Corresponds to 'did' column.
|
||||
int,
|
||||
# Index of the card template (within the NoteType) this QA was built
|
||||
# from. Corresponds to 'ord' column.
|
||||
int,
|
||||
# Tags, separated by space. Corresponds to 'tags' column.
|
||||
str,
|
||||
# Corresponds to 'flds' column. TODO: document.
|
||||
str,
|
||||
# Corresponds to 'cardFlags' column. TODO: document
|
||||
int,
|
||||
]
|
||||
|
||||
TemplateRequirementType = str # Union["all", "any", "none"]
|
||||
# template ordinal, type, list of field ordinals
|
||||
TemplateRequiredFieldOrds = Tuple[int, TemplateRequirementType, List[int]]
|
||||
AllTemplateReqs = List[TemplateRequiredFieldOrds]
|
|
@ -18,8 +18,8 @@ from anki.cards import Card
|
|||
from anki.collection import _Collection
|
||||
from anki.consts import *
|
||||
from anki.lang import _, ngettext
|
||||
from anki.models import NoteType
|
||||
from anki.notes import Note
|
||||
from anki.types import NoteType
|
||||
from anki.utils import (
|
||||
bodyClass,
|
||||
fmtTimeSpan,
|
||||
|
|
Loading…
Reference in a new issue