Added __repr__ functions to common objects

This commit is contained in:
evandrocoan 2020-05-28 18:12:13 -03:00
parent 9594a3ef9b
commit 1e216e47ed
8 changed files with 48 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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()]