diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 483e2d30f..0c947d391 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -64,6 +64,12 @@ class Collection: self.conf = ConfigManager(self) self._loadScheduler() + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["models"] + del d["backend"] + return pprint.pformat(d, width=300) + def name(self) -> Any: n = os.path.splitext(os.path.basename(self.path))[0] return n diff --git a/pylib/anki/db.py b/pylib/anki/db.py index 1800ca14b..b823eb9aa 100644 --- a/pylib/anki/db.py +++ b/pylib/anki/db.py @@ -10,6 +10,7 @@ of add-ons rely on it. """ import os +import pprint import time from sqlite3 import Cursor from sqlite3 import dbapi2 as sqlite @@ -26,6 +27,11 @@ class DB: self.echo = os.environ.get("DBECHO") self.mod = False + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["_db"] + return pprint.pformat(d, width=300) + def execute(self, sql: str, *a, **ka) -> Cursor: s = sql.strip().lower() # mark modified? diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index 29ce7fe5d..87a9dc340 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -4,6 +4,7 @@ from __future__ import annotations import copy +import pprint from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union import anki # pylint: disable=unused-import @@ -80,6 +81,11 @@ class DeckManager: def flush(self): pass + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["col"] + return pprint.pformat(d, width=300) + # Deck save/load ############################################################# diff --git a/pylib/anki/media.py b/pylib/anki/media.py index 6070599d5..fb60db197 100644 --- a/pylib/anki/media.py +++ b/pylib/anki/media.py @@ -4,6 +4,7 @@ from __future__ import annotations import os +import pprint import re import sys import time @@ -60,6 +61,11 @@ class MediaManager: except OSError: raise Exception("invalidTempFolder") + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["col"] + return pprint.pformat(d, width=300) + def connect(self) -> None: if self.col.server: return diff --git a/pylib/anki/models.py b/pylib/anki/models.py index 04ac5061c..ff15c8a3f 100644 --- a/pylib/anki/models.py +++ b/pylib/anki/models.py @@ -4,6 +4,7 @@ from __future__ import annotations import copy +import pprint import time from typing import Any, Dict, List, Optional, Sequence, Tuple, Union @@ -66,6 +67,11 @@ class ModelManager: # do not access this directly! self._cache = {} + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["col"] + return pprint.pformat(d, width=300) + def save( self, m: NoteType = None, diff --git a/pylib/anki/notes.py b/pylib/anki/notes.py index 8d550f198..6227c72e8 100644 --- a/pylib/anki/notes.py +++ b/pylib/anki/notes.py @@ -3,6 +3,7 @@ from __future__ import annotations +import pprint from typing import Any, List, Optional, Sequence, Tuple import anki # pylint: disable=unused-import @@ -66,6 +67,11 @@ class Note: assert self.id != 0 self.col.backend.update_note(self.to_backend_note()) + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["col"] + return pprint.pformat(d, width=300) + def joinedFields(self) -> str: return joinFields(self.fields) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index cab024770..34423eacd 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -3,6 +3,7 @@ from __future__ import annotations +import pprint import random import time from heapq import * @@ -42,6 +43,11 @@ class Scheduler: self._lrnCutoff = 0 self._updateCutoff() + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["col"] + return pprint.pformat(d, width=300) + def getCard(self) -> Optional[Card]: """Pop the next card from the queue. None if finished.""" self._checkDay() diff --git a/pylib/anki/tags.py b/pylib/anki/tags.py index e34863ea8..c339396b5 100644 --- a/pylib/anki/tags.py +++ b/pylib/anki/tags.py @@ -11,6 +11,7 @@ This module manages the tag cache and tags for notes. from __future__ import annotations +import pprint import re from typing import Collection, List, Optional, Tuple @@ -26,6 +27,11 @@ class TagManager: def all(self) -> List[str]: return [t.tag for t in self.col.backend.all_tags()] + def __repr__(self) -> str: + d = dict(self.__dict__) + del d["col"] + return pprint.pformat(d, width=300) + # # List of (tag, usn) def allItems(self) -> List[Tuple[str, int]]: return [(t.tag, t.usn) for t in self.col.backend.all_tags()]