List->Sequence in a bunch of table/browser methods
Most code doesn't require a list specifically, and build a list is an extra step.
This commit is contained in:
parent
13011f9708
commit
28aae21d51
@ -138,13 +138,13 @@ select id from cards where did in %s and queue = {QUEUE_TYPE_REV} and due <= ? l
|
|||||||
# Resetting/rescheduling
|
# Resetting/rescheduling
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def schedule_cards_as_new(self, card_ids: List[CardId]) -> OpChanges:
|
def schedule_cards_as_new(self, card_ids: Sequence[CardId]) -> OpChanges:
|
||||||
"Put cards at the end of the new queue."
|
"Put cards at the end of the new queue."
|
||||||
return self.col._backend.schedule_cards_as_new(card_ids=card_ids, log=True)
|
return self.col._backend.schedule_cards_as_new(card_ids=card_ids, log=True)
|
||||||
|
|
||||||
def set_due_date(
|
def set_due_date(
|
||||||
self,
|
self,
|
||||||
card_ids: List[CardId],
|
card_ids: Sequence[CardId],
|
||||||
days: str,
|
days: str,
|
||||||
config_key: Optional[Config.String.Key.V] = None,
|
config_key: Optional[Config.String.Key.V] = None,
|
||||||
) -> OpChanges:
|
) -> OpChanges:
|
||||||
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import html
|
import html
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, Sequence
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
@ -533,16 +533,16 @@ class Browser(QMainWindow):
|
|||||||
# Menu helpers
|
# Menu helpers
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def selected_cards(self) -> List[CardId]:
|
def selected_cards(self) -> Sequence[CardId]:
|
||||||
return self.table.get_selected_card_ids()
|
return self.table.get_selected_card_ids()
|
||||||
|
|
||||||
def selected_notes(self) -> List[NoteId]:
|
def selected_notes(self) -> Sequence[NoteId]:
|
||||||
return self.table.get_selected_note_ids()
|
return self.table.get_selected_note_ids()
|
||||||
|
|
||||||
def selectedNotesAsCards(self) -> List[CardId]:
|
def selectedNotesAsCards(self) -> Sequence[CardId]:
|
||||||
return self.table.get_card_ids_from_selected_note_ids()
|
return self.table.get_card_ids_from_selected_note_ids()
|
||||||
|
|
||||||
def oneModelNotes(self) -> List[NoteId]:
|
def oneModelNotes(self) -> Sequence[NoteId]:
|
||||||
sf = self.selected_notes()
|
sf = self.selected_notes()
|
||||||
if not sf:
|
if not sf:
|
||||||
return []
|
return []
|
||||||
@ -742,7 +742,7 @@ where id in %s"""
|
|||||||
def _on_export_notes(self) -> None:
|
def _on_export_notes(self) -> None:
|
||||||
cids = self.selectedNotesAsCards()
|
cids = self.selectedNotesAsCards()
|
||||||
if cids:
|
if cids:
|
||||||
ExportDialog(self.mw, cids=cids)
|
ExportDialog(self.mw, cids=list(cids))
|
||||||
|
|
||||||
# Flags & Marking
|
# Flags & Marking
|
||||||
######################################################################
|
######################################################################
|
||||||
@ -1027,7 +1027,7 @@ where id in %s"""
|
|||||||
|
|
||||||
|
|
||||||
class ChangeModel(QDialog):
|
class ChangeModel(QDialog):
|
||||||
def __init__(self, browser: Browser, nids: List[NoteId]) -> None:
|
def __init__(self, browser: Browser, nids: Sequence[NoteId]) -> None:
|
||||||
QDialog.__init__(self, browser)
|
QDialog.__init__(self, browser)
|
||||||
self.browser = browser
|
self.browser = browser
|
||||||
self.nids = nids
|
self.nids = nids
|
||||||
@ -1198,7 +1198,7 @@ class ChangeModel(QDialog):
|
|||||||
b.mw.progress.start()
|
b.mw.progress.start()
|
||||||
b.begin_reset()
|
b.begin_reset()
|
||||||
mm = b.mw.col.models
|
mm = b.mw.col.models
|
||||||
mm.change(self.oldModel, self.nids, self.targetModel, fmap, cmap)
|
mm.change(self.oldModel, list(self.nids), self.targetModel, fmap, cmap)
|
||||||
b.search()
|
b.search()
|
||||||
b.end_reset()
|
b.end_reset()
|
||||||
b.mw.progress.finish()
|
b.mw.progress.finish()
|
||||||
|
@ -21,7 +21,7 @@ def set_due_date_dialog(
|
|||||||
*,
|
*,
|
||||||
mw: aqt.AnkiQt,
|
mw: aqt.AnkiQt,
|
||||||
parent: QWidget,
|
parent: QWidget,
|
||||||
card_ids: List[CardId],
|
card_ids: Sequence[CardId],
|
||||||
config_key: Optional[Config.String.Key.V],
|
config_key: Optional[Config.String.Key.V],
|
||||||
) -> None:
|
) -> None:
|
||||||
if not card_ids:
|
if not card_ids:
|
||||||
@ -54,7 +54,7 @@ def set_due_date_dialog(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def forget_cards(*, mw: aqt.AnkiQt, parent: QWidget, card_ids: List[CardId]) -> None:
|
def forget_cards(*, mw: aqt.AnkiQt, parent: QWidget, card_ids: Sequence[CardId]) -> None:
|
||||||
if not card_ids:
|
if not card_ids:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ from aqt.utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
Item = Union[CardId, NoteId]
|
Item = Union[CardId, NoteId]
|
||||||
ItemList = Union[List[CardId], List[NoteId]]
|
ItemList = Union[Sequence[CardId], Sequence[NoteId]]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -118,13 +118,13 @@ class Table:
|
|||||||
|
|
||||||
# Get ids
|
# Get ids
|
||||||
|
|
||||||
def get_selected_card_ids(self) -> List[CardId]:
|
def get_selected_card_ids(self) -> Sequence[CardId]:
|
||||||
return self._model.get_card_ids(self._selected())
|
return self._model.get_card_ids(self._selected())
|
||||||
|
|
||||||
def get_selected_note_ids(self) -> List[NoteId]:
|
def get_selected_note_ids(self) -> Sequence[NoteId]:
|
||||||
return self._model.get_note_ids(self._selected())
|
return self._model.get_note_ids(self._selected())
|
||||||
|
|
||||||
def get_card_ids_from_selected_note_ids(self) -> List[CardId]:
|
def get_card_ids_from_selected_note_ids(self) -> Sequence[CardId]:
|
||||||
return self._state.card_ids_from_note_ids(self.get_selected_note_ids())
|
return self._state.card_ids_from_note_ids(self.get_selected_note_ids())
|
||||||
|
|
||||||
# Selecting
|
# Selecting
|
||||||
@ -531,12 +531,12 @@ class ItemState(ABC):
|
|||||||
|
|
||||||
# Stateless Helpers
|
# Stateless Helpers
|
||||||
|
|
||||||
def note_ids_from_card_ids(self, items: Sequence[Item]) -> List[NoteId]:
|
def note_ids_from_card_ids(self, items: Sequence[Item]) -> Sequence[NoteId]:
|
||||||
return self.col.db.list(
|
return self.col.db.list(
|
||||||
f"select distinct nid from cards where id in {ids2str(items)}"
|
f"select distinct nid from cards where id in {ids2str(items)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def card_ids_from_note_ids(self, items: Sequence[Item]) -> List[CardId]:
|
def card_ids_from_note_ids(self, items: Sequence[Item]) -> Sequence[CardId]:
|
||||||
return self.col.db.list(f"select id from cards where nid in {ids2str(items)}")
|
return self.col.db.list(f"select id from cards where nid in {ids2str(items)}")
|
||||||
|
|
||||||
# Columns and sorting
|
# Columns and sorting
|
||||||
@ -590,11 +590,11 @@ class ItemState(ABC):
|
|||||||
"""Return the appropriate item id for a card id."""
|
"""Return the appropriate item id for a card id."""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_card_ids(self, items: List[Item]) -> List[CardId]:
|
def get_card_ids(self, items: Sequence[Item]) -> Sequence[CardId]:
|
||||||
"""Return the card ids for the given item ids."""
|
"""Return the card ids for the given item ids."""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_note_ids(self, items: List[Item]) -> List[NoteId]:
|
def get_note_ids(self, items: Sequence[Item]) -> Sequence[NoteId]:
|
||||||
"""Return the note ids for the given item ids."""
|
"""Return the note ids for the given item ids."""
|
||||||
|
|
||||||
# Toggle
|
# Toggle
|
||||||
@ -694,10 +694,10 @@ class CardState(ItemState):
|
|||||||
def get_item_from_card_id(self, card: CardId) -> Item:
|
def get_item_from_card_id(self, card: CardId) -> Item:
|
||||||
return card
|
return card
|
||||||
|
|
||||||
def get_card_ids(self, items: List[Item]) -> List[CardId]:
|
def get_card_ids(self, items: Sequence[Item]) -> Sequence[CardId]:
|
||||||
return list(map(CardId, items))
|
return cast(Sequence[CardId], items)
|
||||||
|
|
||||||
def get_note_ids(self, items: List[Item]) -> List[NoteId]:
|
def get_note_ids(self, items: Sequence[Item]) -> Sequence[NoteId]:
|
||||||
return super().note_ids_from_card_ids(items)
|
return super().note_ids_from_card_ids(items)
|
||||||
|
|
||||||
def toggle_state(self) -> NoteState:
|
def toggle_state(self) -> NoteState:
|
||||||
@ -706,7 +706,7 @@ class CardState(ItemState):
|
|||||||
def get_new_item(self, old_item: Item) -> CardId:
|
def get_new_item(self, old_item: Item) -> CardId:
|
||||||
return super().card_ids_from_note_ids([old_item])[0]
|
return super().card_ids_from_note_ids([old_item])[0]
|
||||||
|
|
||||||
def get_new_items(self, old_items: Sequence[Item]) -> List[CardId]:
|
def get_new_items(self, old_items: Sequence[Item]) -> Sequence[CardId]:
|
||||||
return super().card_ids_from_note_ids(old_items)
|
return super().card_ids_from_note_ids(old_items)
|
||||||
|
|
||||||
|
|
||||||
@ -782,11 +782,11 @@ class NoteState(ItemState):
|
|||||||
def get_item_from_card_id(self, card: CardId) -> Item:
|
def get_item_from_card_id(self, card: CardId) -> Item:
|
||||||
return self.get_card(card).note().id
|
return self.get_card(card).note().id
|
||||||
|
|
||||||
def get_card_ids(self, items: List[Item]) -> List[CardId]:
|
def get_card_ids(self, items: Sequence[Item]) -> Sequence[CardId]:
|
||||||
return super().card_ids_from_note_ids(items)
|
return super().card_ids_from_note_ids(items)
|
||||||
|
|
||||||
def get_note_ids(self, items: List[Item]) -> List[NoteId]:
|
def get_note_ids(self, items: Sequence[Item]) -> Sequence[NoteId]:
|
||||||
return list(map(NoteId, items))
|
return cast(Sequence[NoteId], items)
|
||||||
|
|
||||||
def toggle_state(self) -> CardState:
|
def toggle_state(self) -> CardState:
|
||||||
return CardState(self.col)
|
return CardState(self.col)
|
||||||
@ -794,7 +794,7 @@ class NoteState(ItemState):
|
|||||||
def get_new_item(self, old_item: Item) -> NoteId:
|
def get_new_item(self, old_item: Item) -> NoteId:
|
||||||
return super().note_ids_from_card_ids([old_item])[0]
|
return super().note_ids_from_card_ids([old_item])[0]
|
||||||
|
|
||||||
def get_new_items(self, old_items: Sequence[Item]) -> List[NoteId]:
|
def get_new_items(self, old_items: Sequence[Item]) -> Sequence[NoteId]:
|
||||||
return super().note_ids_from_card_ids(old_items)
|
return super().note_ids_from_card_ids(old_items)
|
||||||
|
|
||||||
|
|
||||||
@ -959,13 +959,13 @@ class DataModel(QAbstractTableModel):
|
|||||||
def get_item(self, index: QModelIndex) -> Item:
|
def get_item(self, index: QModelIndex) -> Item:
|
||||||
return self._items[index.row()]
|
return self._items[index.row()]
|
||||||
|
|
||||||
def get_items(self, indices: List[QModelIndex]) -> List[Item]:
|
def get_items(self, indices: List[QModelIndex]) -> Sequence[Item]:
|
||||||
return [self.get_item(index) for index in indices]
|
return [self.get_item(index) for index in indices]
|
||||||
|
|
||||||
def get_card_ids(self, indices: List[QModelIndex]) -> List[CardId]:
|
def get_card_ids(self, indices: List[QModelIndex]) -> Sequence[CardId]:
|
||||||
return self._state.get_card_ids(self.get_items(indices))
|
return self._state.get_card_ids(self.get_items(indices))
|
||||||
|
|
||||||
def get_note_ids(self, indices: List[QModelIndex]) -> List[NoteId]:
|
def get_note_ids(self, indices: List[QModelIndex]) -> Sequence[NoteId]:
|
||||||
return self._state.get_note_ids(self.get_items(indices))
|
return self._state.get_note_ids(self.get_items(indices))
|
||||||
|
|
||||||
# Get row numbers from items
|
# Get row numbers from items
|
||||||
|
Loading…
Reference in New Issue
Block a user