mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
pass weakref in from storage to fix type checking/code completion
This commit is contained in:
parent
db1508e27c
commit
63e3357068
3 changed files with 5 additions and 4 deletions
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import weakref
|
|
||||||
from typing import Any, Iterable, List, Optional, Sequence, Union
|
from typing import Any, Iterable, List, Optional, Sequence, Union
|
||||||
|
|
||||||
import anki
|
import anki
|
||||||
|
@ -28,7 +27,7 @@ class DBProxy:
|
||||||
###############
|
###############
|
||||||
|
|
||||||
def __init__(self, backend: anki.rsbackend.RustBackend, path: str) -> None:
|
def __init__(self, backend: anki.rsbackend.RustBackend, path: str) -> None:
|
||||||
self._backend = weakref.proxy(backend)
|
self._backend = backend
|
||||||
self._path = path
|
self._path = path
|
||||||
self.mod = False
|
self.mod = False
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from typing import (
|
||||||
NewType,
|
NewType,
|
||||||
NoReturn,
|
NoReturn,
|
||||||
Optional,
|
Optional,
|
||||||
|
Sequence,
|
||||||
Tuple,
|
Tuple,
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
@ -387,7 +388,7 @@ class RustBackend:
|
||||||
self._run_command(pb.BackendInput(restore_trash=pb.Empty()))
|
self._run_command(pb.BackendInput(restore_trash=pb.Empty()))
|
||||||
|
|
||||||
def db_query(
|
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]:
|
) -> List[DBRow]:
|
||||||
return self._db_command(
|
return self._db_command(
|
||||||
dict(kind="query", sql=sql, args=args, first_row_only=first_row_only)
|
dict(kind="query", sql=sql, args=args, first_row_only=first_row_only)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import weakref
|
||||||
from typing import Any, Dict, Optional, Tuple
|
from typing import Any, Dict, Optional, Tuple
|
||||||
|
|
||||||
from anki.collection import _Collection
|
from anki.collection import _Collection
|
||||||
|
@ -38,7 +39,7 @@ def Collection(path: str, server: Optional[ServerData] = None) -> _Collection:
|
||||||
backend = RustBackend(
|
backend = RustBackend(
|
||||||
path, media_dir, media_db, log_path, server=server is not None
|
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.begin()
|
||||||
db.setAutocommit(True)
|
db.setAutocommit(True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue