mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
update to latest mypy_protobuf
The handling of enum types has improved - we no longer need to import separate types at typechecking time.
This commit is contained in:
parent
86f8cba22c
commit
168963460f
12 changed files with 26 additions and 82 deletions
|
@ -72,7 +72,7 @@ mypy-extensions==0.4.3
|
||||||
# via
|
# via
|
||||||
# black
|
# black
|
||||||
# mypy
|
# mypy
|
||||||
mypy-protobuf==1.24
|
mypy-protobuf==2.1
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
mypy==0.800
|
mypy==0.800
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
|
@ -156,7 +156,7 @@ wrapt==1.12.1
|
||||||
# The following packages are considered to be unsafe in a requirements file:
|
# The following packages are considered to be unsafe in a requirements file:
|
||||||
pip==21.0.1
|
pip==21.0.1
|
||||||
# via pip-tools
|
# via pip-tools
|
||||||
setuptools==52.0.0
|
setuptools==53.0.0
|
||||||
# via jsonschema
|
# via jsonschema
|
||||||
|
|
||||||
# manually added for now; ensure it and the earlier winrt are not removed on update
|
# manually added for now; ensure it and the earlier winrt are not removed on update
|
||||||
|
|
|
@ -4,22 +4,19 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
|
from typing import Any, Dict, List, Optional, Sequence, Union
|
||||||
|
|
||||||
import anki.buildinfo
|
import anki.buildinfo
|
||||||
from anki._backend.generated import RustBackendGenerated
|
from anki._backend.generated import RustBackendGenerated
|
||||||
from anki.dbproxy import Row as DBRow
|
from anki.dbproxy import Row as DBRow
|
||||||
from anki.dbproxy import ValueForDB
|
from anki.dbproxy import ValueForDB
|
||||||
from anki.errors import backend_exception_to_pylib
|
from anki.errors import backend_exception_to_pylib
|
||||||
from anki.lang import FormatTimeSpanContext
|
from anki.lang import TR, FormatTimeSpanContext
|
||||||
from anki.utils import from_json_bytes, to_json_bytes
|
from anki.utils import from_json_bytes, to_json_bytes
|
||||||
|
|
||||||
from . import backend_pb2 as pb
|
from . import backend_pb2 as pb
|
||||||
from . import rsbridge
|
from . import rsbridge
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from anki.lang import FormatTimeSpanContextValue, TRValue
|
|
||||||
|
|
||||||
# pylint: disable=c-extension-no-member
|
# pylint: disable=c-extension-no-member
|
||||||
assert rsbridge.buildhash() == anki.buildinfo.buildhash
|
assert rsbridge.buildhash() == anki.buildinfo.buildhash
|
||||||
|
|
||||||
|
@ -85,13 +82,13 @@ class RustBackend(RustBackendGenerated):
|
||||||
err.ParseFromString(err_bytes)
|
err.ParseFromString(err_bytes)
|
||||||
raise backend_exception_to_pylib(err)
|
raise backend_exception_to_pylib(err)
|
||||||
|
|
||||||
def translate(self, key: TRValue, **kwargs: Union[str, int, float]) -> str:
|
def translate(self, key: TR.V, **kwargs: Union[str, int, float]) -> str:
|
||||||
return self.translate_string(translate_string_in(key, **kwargs))
|
return self.translate_string(translate_string_in(key, **kwargs))
|
||||||
|
|
||||||
def format_time_span(
|
def format_time_span(
|
||||||
self,
|
self,
|
||||||
seconds: float,
|
seconds: float,
|
||||||
context: FormatTimeSpanContextValue = FormatTimeSpanContext.INTERVALS,
|
context: FormatTimeSpanContext.V = FormatTimeSpanContext.INTERVALS,
|
||||||
) -> str:
|
) -> str:
|
||||||
print(
|
print(
|
||||||
"please use col.format_timespan() instead of col.backend.format_time_span()"
|
"please use col.format_timespan() instead of col.backend.format_time_span()"
|
||||||
|
@ -110,7 +107,7 @@ class RustBackend(RustBackendGenerated):
|
||||||
|
|
||||||
|
|
||||||
def translate_string_in(
|
def translate_string_in(
|
||||||
key: TRValue, **kwargs: Union[str, int, float]
|
key: TR.V, **kwargs: Union[str, int, float]
|
||||||
) -> pb.TranslateStringIn:
|
) -> pb.TranslateStringIn:
|
||||||
args = {}
|
args = {}
|
||||||
for (k, v) in kwargs.items():
|
for (k, v) in kwargs.items():
|
||||||
|
|
|
@ -61,7 +61,7 @@ def python_type_inner(field):
|
||||||
elif type == TYPE_MESSAGE:
|
elif type == TYPE_MESSAGE:
|
||||||
return fullname(field.message_type.full_name)
|
return fullname(field.message_type.full_name)
|
||||||
elif type == TYPE_ENUM:
|
elif type == TYPE_ENUM:
|
||||||
return fullname(field.enum_type.full_name) + "Value"
|
return fullname(field.enum_type.full_name) + ".V"
|
||||||
else:
|
else:
|
||||||
raise Exception(f"unknown type: {type}")
|
raise Exception(f"unknown type: {type}")
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import time
|
||||||
import traceback
|
import traceback
|
||||||
import weakref
|
import weakref
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Any, List, Optional, Sequence, Tuple, Union
|
from typing import Any, List, Optional, Sequence, Tuple, Union
|
||||||
|
|
||||||
import anki._backend.backend_pb2 as _pb
|
import anki._backend.backend_pb2 as _pb
|
||||||
import anki.find
|
import anki.find
|
||||||
|
@ -57,13 +57,6 @@ GraphPreferences = _pb.GraphPreferences
|
||||||
BuiltinSortKind = _pb.SortOrder.Builtin.Kind # pylint: disable=no-member
|
BuiltinSortKind = _pb.SortOrder.Builtin.Kind # pylint: disable=no-member
|
||||||
Preferences = _pb.Preferences
|
Preferences = _pb.Preferences
|
||||||
|
|
||||||
# pylint: disable=no-member
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from anki.lang import FormatTimeSpanContextValue, TRValue
|
|
||||||
|
|
||||||
ConfigBoolKeyValue = _pb.ConfigBool.KeyValue
|
|
||||||
BuiltinSortKindValue = _pb.SortOrder.Builtin.KindValue
|
|
||||||
|
|
||||||
|
|
||||||
class Collection:
|
class Collection:
|
||||||
sched: Union[V1Scheduler, V2Scheduler]
|
sched: Union[V1Scheduler, V2Scheduler]
|
||||||
|
@ -118,13 +111,13 @@ class Collection:
|
||||||
# I18n/messages
|
# I18n/messages
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def tr(self, key: TRValue, **kwargs: Union[str, int, float]) -> str:
|
def tr(self, key: TR.V, **kwargs: Union[str, int, float]) -> str:
|
||||||
return self._backend.translate(key, **kwargs)
|
return self._backend.translate(key, **kwargs)
|
||||||
|
|
||||||
def format_timespan(
|
def format_timespan(
|
||||||
self,
|
self,
|
||||||
seconds: float,
|
seconds: float,
|
||||||
context: FormatTimeSpanContextValue = FormatTimeSpanContext.INTERVALS,
|
context: FormatTimeSpanContext.V = FormatTimeSpanContext.INTERVALS,
|
||||||
) -> str:
|
) -> str:
|
||||||
return self._backend.format_timespan(seconds=seconds, context=context)
|
return self._backend.format_timespan(seconds=seconds, context=context)
|
||||||
|
|
||||||
|
@ -468,7 +461,7 @@ class Collection:
|
||||||
def find_cards(
|
def find_cards(
|
||||||
self,
|
self,
|
||||||
query: str,
|
query: str,
|
||||||
order: Union[bool, str, BuiltinSortKindValue] = False,
|
order: Union[bool, str, BuiltinSortKind.V] = False,
|
||||||
reverse: bool = False,
|
reverse: bool = False,
|
||||||
) -> Sequence[int]:
|
) -> Sequence[int]:
|
||||||
if isinstance(order, str):
|
if isinstance(order, str):
|
||||||
|
@ -539,6 +532,7 @@ class Collection:
|
||||||
# Search Strings
|
# Search Strings
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
# pylint: disable=no-member
|
||||||
def build_search_string(
|
def build_search_string(
|
||||||
self,
|
self,
|
||||||
*terms: Union[str, SearchTerm],
|
*terms: Union[str, SearchTerm],
|
||||||
|
@ -592,10 +586,10 @@ class Collection:
|
||||||
"This is a debugging aid. Prefer .get_config() when you know the key you need."
|
"This is a debugging aid. Prefer .get_config() when you know the key you need."
|
||||||
return from_json_bytes(self._backend.get_all_config())
|
return from_json_bytes(self._backend.get_all_config())
|
||||||
|
|
||||||
def get_config_bool(self, key: ConfigBoolKeyValue) -> bool:
|
def get_config_bool(self, key: ConfigBoolKey.V) -> bool:
|
||||||
return self._backend.get_config_bool(key)
|
return self._backend.get_config_bool(key)
|
||||||
|
|
||||||
def set_config_bool(self, key: ConfigBoolKeyValue, value: bool) -> None:
|
def set_config_bool(self, key: ConfigBoolKey.V, value: bool) -> None:
|
||||||
self.setMod()
|
self.setMod()
|
||||||
self._backend.set_config_bool(key=key, value=value)
|
self._backend.set_config_bool(key=key, value=value)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import locale
|
import locale
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING, Any, Optional, Tuple
|
from typing import Any, Optional, Tuple
|
||||||
|
|
||||||
import anki
|
import anki
|
||||||
import anki._backend.backend_pb2 as _pb
|
import anki._backend.backend_pb2 as _pb
|
||||||
|
@ -15,11 +15,6 @@ import anki._backend.fluent_pb2 as _fluent_pb
|
||||||
TR = _fluent_pb.FluentString
|
TR = _fluent_pb.FluentString
|
||||||
FormatTimeSpanContext = _pb.FormatTimespanIn.Context # pylint: disable=no-member
|
FormatTimeSpanContext = _pb.FormatTimespanIn.Context # pylint: disable=no-member
|
||||||
|
|
||||||
# pylint: disable=no-member
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
TRValue = _fluent_pb.FluentStringValue
|
|
||||||
FormatTimeSpanContextValue = _pb.FormatTimespanIn.ContextValue
|
|
||||||
|
|
||||||
langs = sorted(
|
langs = sorted(
|
||||||
[
|
[
|
||||||
("Afrikaans", "af_ZA"),
|
("Afrikaans", "af_ZA"),
|
||||||
|
|
|
@ -7,11 +7,6 @@
|
||||||
#
|
#
|
||||||
# pylint: disable=unused-import
|
# pylint: disable=unused-import
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from anki.decks import DeckTreeNode
|
from anki.decks import DeckTreeNode
|
||||||
from anki.errors import InvalidInput, NotFoundError
|
from anki.errors import InvalidInput, NotFoundError
|
||||||
from anki.lang import FormatTimeSpanContext
|
from anki.lang import FormatTimeSpanContext
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from anki.lang import FormatTimeSpanContextValue, TRValue
|
|
||||||
|
|
|
@ -7,17 +7,7 @@ import pprint
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from heapq import *
|
from heapq import *
|
||||||
from typing import (
|
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
|
||||||
TYPE_CHECKING,
|
|
||||||
Any,
|
|
||||||
Callable,
|
|
||||||
Dict,
|
|
||||||
List,
|
|
||||||
Optional,
|
|
||||||
Sequence,
|
|
||||||
Tuple,
|
|
||||||
Union,
|
|
||||||
)
|
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki # pylint: disable=unused-import
|
||||||
import anki._backend.backend_pb2 as _pb
|
import anki._backend.backend_pb2 as _pb
|
||||||
|
@ -35,13 +25,6 @@ SchedTimingToday = _pb.SchedTimingTodayOut
|
||||||
|
|
||||||
UnburyCurrentDeckMode = _pb.UnburyCardsInCurrentDeckIn.Mode # pylint:disable=no-member
|
UnburyCurrentDeckMode = _pb.UnburyCardsInCurrentDeckIn.Mode # pylint:disable=no-member
|
||||||
BuryOrSuspendMode = _pb.BuryOrSuspendCardsIn.Mode # pylint:disable=no-member
|
BuryOrSuspendMode = _pb.BuryOrSuspendCardsIn.Mode # pylint:disable=no-member
|
||||||
if TYPE_CHECKING:
|
|
||||||
UnburyCurrentDeckModeValue = (
|
|
||||||
_pb.UnburyCardsInCurrentDeckIn.ModeValue # pylint:disable=no-member
|
|
||||||
)
|
|
||||||
BuryOrSuspendModeValue = (
|
|
||||||
_pb.BuryOrSuspendCardsIn.ModeValue # pylint:disable=no-member
|
|
||||||
)
|
|
||||||
|
|
||||||
# card types: 0=new, 1=lrn, 2=rev, 3=relrn
|
# card types: 0=new, 1=lrn, 2=rev, 3=relrn
|
||||||
# queue types: 0=new, 1=(re)lrn, 2=rev, 3=day (re)lrn,
|
# queue types: 0=new, 1=(re)lrn, 2=rev, 3=day (re)lrn,
|
||||||
|
@ -1332,7 +1315,7 @@ due = (case when odue>0 then odue else due end), odue = 0, odid = 0, usn = ? whe
|
||||||
|
|
||||||
def unbury_cards_in_current_deck(
|
def unbury_cards_in_current_deck(
|
||||||
self,
|
self,
|
||||||
mode: UnburyCurrentDeckModeValue = UnburyCurrentDeckMode.ALL,
|
mode: UnburyCurrentDeckMode.V = UnburyCurrentDeckMode.ALL,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.col._backend.unbury_cards_in_current_deck(mode)
|
self.col._backend.unbury_cards_in_current_deck(mode)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Callable, List, Tuple
|
from typing import Callable, List, Tuple
|
||||||
|
|
||||||
import anki
|
import anki
|
||||||
import anki._backend.backend_pb2 as _pb
|
import anki._backend.backend_pb2 as _pb
|
||||||
|
@ -12,18 +12,13 @@ from anki.utils import from_json_bytes
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
StockNotetypeKind = _pb.StockNoteType.Kind
|
StockNotetypeKind = _pb.StockNoteType.Kind
|
||||||
|
|
||||||
# pylint: disable=no-member
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
StockNotetypeKindValue = _pb.StockNoteType.KindValue
|
|
||||||
|
|
||||||
|
|
||||||
# add-on authors can add ("note type name", function_like_addBasicModel)
|
# add-on authors can add ("note type name", function_like_addBasicModel)
|
||||||
# to this list to have it shown in the add/clone note type screen
|
# to this list to have it shown in the add/clone note type screen
|
||||||
models: List[Tuple] = []
|
models: List[Tuple] = []
|
||||||
|
|
||||||
|
|
||||||
def _add_stock_notetype(
|
def _add_stock_notetype(
|
||||||
col: anki.collection.Collection, kind: StockNotetypeKindValue
|
col: anki.collection.Collection, kind: StockNotetypeKind.V
|
||||||
) -> anki.models.NoteType:
|
) -> anki.models.NoteType:
|
||||||
m = from_json_bytes(col._backend.get_stock_notetype_legacy(kind))
|
m = from_json_bytes(col._backend.get_stock_notetype_legacy(kind))
|
||||||
col.models.add(m)
|
col.models.add(m)
|
||||||
|
|
|
@ -116,7 +116,7 @@ def after_full_sync() -> None:
|
||||||
|
|
||||||
def get_method(
|
def get_method(
|
||||||
method_str: str,
|
method_str: str,
|
||||||
) -> Optional[SyncServerMethodIn.MethodValue]: # pylint: disable=no-member
|
) -> Optional[SyncServerMethodIn.Method.V]: # pylint: disable=no-member
|
||||||
s = method_str
|
s = method_str
|
||||||
if s == "hostKey":
|
if s == "hostKey":
|
||||||
return Method.HOST_KEY
|
return Method.HOST_KEY
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from mypy_protobuf import main
|
from mypy_protobuf.main import main
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
|
sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
|
||||||
|
|
|
@ -6,17 +6,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from concurrent.futures import Future
|
from concurrent.futures import Future
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import (
|
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, cast
|
||||||
TYPE_CHECKING,
|
|
||||||
Any,
|
|
||||||
Dict,
|
|
||||||
Iterable,
|
|
||||||
List,
|
|
||||||
Optional,
|
|
||||||
Sequence,
|
|
||||||
Tuple,
|
|
||||||
cast,
|
|
||||||
)
|
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from anki.collection import ConfigBoolKey, SearchTerm
|
from anki.collection import ConfigBoolKey, SearchTerm
|
||||||
|
@ -38,9 +28,6 @@ from aqt.utils import (
|
||||||
tr,
|
tr,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from anki.collection import ConfigBoolKeyValue, TRValue
|
|
||||||
|
|
||||||
|
|
||||||
class SidebarItemType(Enum):
|
class SidebarItemType(Enum):
|
||||||
ROOT = 0
|
ROOT = 0
|
||||||
|
@ -512,9 +499,9 @@ class SidebarTreeView(QTreeView):
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
root: SidebarItem,
|
root: SidebarItem,
|
||||||
name: TRValue,
|
name: TR.V,
|
||||||
icon: str,
|
icon: str,
|
||||||
collapse_key: ConfigBoolKeyValue,
|
collapse_key: ConfigBoolKey.V,
|
||||||
type: Optional[SidebarItemType] = None,
|
type: Optional[SidebarItemType] = None,
|
||||||
) -> SidebarItem:
|
) -> SidebarItem:
|
||||||
def update(expanded: bool) -> None:
|
def update(expanded: bool) -> None:
|
||||||
|
|
|
@ -44,8 +44,6 @@ from aqt.qt import *
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from anki.lang import TRValue
|
|
||||||
|
|
||||||
TextFormat = Union[Literal["plain", "rich"]]
|
TextFormat = Union[Literal["plain", "rich"]]
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +66,7 @@ def locale_dir() -> str:
|
||||||
return os.path.join(aqt_data_folder(), "locale")
|
return os.path.join(aqt_data_folder(), "locale")
|
||||||
|
|
||||||
|
|
||||||
def tr(key: TRValue, **kwargs: Union[str, int, float]) -> str:
|
def tr(key: TR.V, **kwargs: Union[str, int, float]) -> str:
|
||||||
"Shortcut to access Fluent translations."
|
"Shortcut to access Fluent translations."
|
||||||
return anki.lang.current_i18n.translate(key, **kwargs)
|
return anki.lang.current_i18n.translate(key, **kwargs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue