exhaustiveness checks on literals are now possible with the move to py38
This commit is contained in:
parent
91a9307c39
commit
af92bb5e93
@ -32,7 +32,6 @@ from anki.dbproxy import Row as DBRow
|
|||||||
from anki.dbproxy import ValueForDB
|
from anki.dbproxy import ValueForDB
|
||||||
from anki.fluent_pb2 import FluentString as TR
|
from anki.fluent_pb2 import FluentString as TR
|
||||||
from anki.rsbackend_gen import RustBackendGenerated
|
from anki.rsbackend_gen import RustBackendGenerated
|
||||||
from anki.types import assert_impossible_literal
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from anki.fluent_pb2 import FluentStringValue as TRValue
|
from anki.fluent_pb2 import FluentStringValue as TRValue
|
||||||
|
@ -1,16 +1,5 @@
|
|||||||
import enum
|
from typing import NoReturn
|
||||||
from typing import Any, NoReturn
|
|
||||||
|
|
||||||
|
|
||||||
class _Impossible(enum.Enum):
|
def assert_exhaustive(arg: NoReturn) -> NoReturn:
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def assert_impossible(arg: NoReturn) -> NoReturn:
|
|
||||||
raise Exception(f"unexpected arg received: {type(arg)} {arg}")
|
|
||||||
|
|
||||||
|
|
||||||
# mypy is not yet smart enough to do exhaustiveness checking on literal types,
|
|
||||||
# so this will fail at runtime instead of typecheck time :-(
|
|
||||||
def assert_impossible_literal(arg: Any) -> NoReturn:
|
|
||||||
raise Exception(f"unexpected arg received: {type(arg)} {arg}")
|
raise Exception(f"unexpected arg received: {type(arg)} {arg}")
|
||||||
|
@ -16,7 +16,7 @@ from anki.rsbackend import (
|
|||||||
NetworkError,
|
NetworkError,
|
||||||
ProgressKind,
|
ProgressKind,
|
||||||
)
|
)
|
||||||
from anki.types import assert_impossible
|
from anki.types import assert_exhaustive
|
||||||
from anki.utils import intTime
|
from anki.utils import intTime
|
||||||
from aqt import gui_hooks
|
from aqt import gui_hooks
|
||||||
from aqt.qt import QDialog, QDialogButtonBox, QPushButton, QTextCursor, QTimer, qconnect
|
from aqt.qt import QDialog, QDialogButtonBox, QPushButton, QTextCursor, QTimer, qconnect
|
||||||
@ -206,7 +206,7 @@ class MediaSyncDialog(QDialog):
|
|||||||
elif isinstance(entry.entry, MediaSyncProgress):
|
elif isinstance(entry.entry, MediaSyncProgress):
|
||||||
txt = self._logentry_to_text(entry.entry)
|
txt = self._logentry_to_text(entry.entry)
|
||||||
else:
|
else:
|
||||||
assert_impossible(entry.entry)
|
assert_exhaustive(entry.entry)
|
||||||
return self._time_and_text(entry.time, txt)
|
return self._time_and_text(entry.time, txt)
|
||||||
|
|
||||||
def _logentry_to_text(self, e: MediaSyncProgress) -> str:
|
def _logentry_to_text(self, e: MediaSyncProgress) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user