From 63e335706812633fc0f226d29c6363f9f1232f8c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 6 Mar 2020 10:16:39 +1000 Subject: [PATCH] pass weakref in from storage to fix type checking/code completion --- pylib/anki/dbproxy.py | 3 +-- pylib/anki/rsbackend.py | 3 ++- pylib/anki/storage.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pylib/anki/dbproxy.py b/pylib/anki/dbproxy.py index 197e5ef21..e2392fbef 100644 --- a/pylib/anki/dbproxy.py +++ b/pylib/anki/dbproxy.py @@ -3,7 +3,6 @@ from __future__ import annotations -import weakref from typing import Any, Iterable, List, Optional, Sequence, Union import anki @@ -28,7 +27,7 @@ class DBProxy: ############### def __init__(self, backend: anki.rsbackend.RustBackend, path: str) -> None: - self._backend = weakref.proxy(backend) + self._backend = backend self._path = path self.mod = False diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index b098aaa10..a15444a53 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -14,6 +14,7 @@ from typing import ( NewType, NoReturn, Optional, + Sequence, Tuple, Union, ) @@ -387,7 +388,7 @@ class RustBackend: self._run_command(pb.BackendInput(restore_trash=pb.Empty())) def db_query( - self, sql: str, args: List[ValueForDB], first_row_only: bool + self, sql: str, args: Sequence[ValueForDB], first_row_only: bool ) -> List[DBRow]: return self._db_command( dict(kind="query", sql=sql, args=args, first_row_only=first_row_only) diff --git a/pylib/anki/storage.py b/pylib/anki/storage.py index e873a38f8..cdb5fd830 100644 --- a/pylib/anki/storage.py +++ b/pylib/anki/storage.py @@ -4,6 +4,7 @@ import copy import json import os +import weakref from typing import Any, Dict, Optional, Tuple from anki.collection import _Collection @@ -38,7 +39,7 @@ def Collection(path: str, server: Optional[ServerData] = None) -> _Collection: backend = RustBackend( path, media_dir, media_db, log_path, server=server is not None ) - db = DBProxy(backend, path) + db = DBProxy(weakref.proxy(backend), path) db.begin() db.setAutocommit(True)