exhaustiveness checks on literals are now possible with the move to py38

This commit is contained in:
Damien Elmes 2020-12-18 16:50:55 +10:00
parent 91a9307c39
commit af92bb5e93
3 changed files with 4 additions and 16 deletions

View File

@ -32,7 +32,6 @@ from anki.dbproxy import Row as DBRow
from anki.dbproxy import ValueForDB
from anki.fluent_pb2 import FluentString as TR
from anki.rsbackend_gen import RustBackendGenerated
from anki.types import assert_impossible_literal
if TYPE_CHECKING:
from anki.fluent_pb2 import FluentStringValue as TRValue

View File

@ -1,16 +1,5 @@
import enum
from typing import Any, NoReturn
from typing import NoReturn
class _Impossible(enum.Enum):
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:
def assert_exhaustive(arg: NoReturn) -> NoReturn:
raise Exception(f"unexpected arg received: {type(arg)} {arg}")

View File

@ -16,7 +16,7 @@ from anki.rsbackend import (
NetworkError,
ProgressKind,
)
from anki.types import assert_impossible
from anki.types import assert_exhaustive
from anki.utils import intTime
from aqt import gui_hooks
from aqt.qt import QDialog, QDialogButtonBox, QPushButton, QTextCursor, QTimer, qconnect
@ -206,7 +206,7 @@ class MediaSyncDialog(QDialog):
elif isinstance(entry.entry, MediaSyncProgress):
txt = self._logentry_to_text(entry.entry)
else:
assert_impossible(entry.entry)
assert_exhaustive(entry.entry)
return self._time_and_text(entry.time, txt)
def _logentry_to_text(self, e: MediaSyncProgress) -> str: