mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Added __repr__ functions to common objects
This commit is contained in:
parent
9594a3ef9b
commit
1e216e47ed
8 changed files with 48 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
#############################################################
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()]
|
||||
|
|
Loading…
Reference in a new issue