From 0e9a8e18c13ee26e9383c003ebebba989bd6fb97 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 26 Apr 2022 21:46:52 +1000 Subject: [PATCH] Avoid kwargs in pb message creation, so typechecking is not lost Protobuf's behaviour is rather subtle and I had to dig through the docs to figure it out: set a field on a submessage to automatically assign the submessage to the parent, or call SetInParent() to persist a default version of the field you specified. --- pylib/.pylintrc | 1 + pylib/anki/collection.py | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pylib/.pylintrc b/pylib/.pylintrc index c9d947569..12152de9e 100644 --- a/pylib/.pylintrc +++ b/pylib/.pylintrc @@ -22,6 +22,7 @@ ignored-classes= CustomStudyRequest, Cram, ScheduleCardsAsNewRequest, + ExportAnkiPackageRequest, [REPORTS] output-format=colorized diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index b8fd54bbf..a0c023f54 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -379,19 +379,18 @@ class Collection(DeprecatedNamesMixin): with_scheduling: bool, with_media: bool, ) -> int: - if selector is None: - selector_kwarg: dict[str, Any] = {"whole_collection": Empty()} - elif isinstance(selector, list): - selector_kwarg = {"note_ids": NoteIds(note_ids=selector)} - else: - selector_kwarg = {"deck_id": selector} request = ExportAnkiPackageRequest( out_path=out_path, with_scheduling=with_scheduling, with_media=with_media, legacy=True, - **selector_kwarg, ) + if selector is None: + request.whole_collection.SetInParent() + elif isinstance(selector, list): + request.note_ids.note_ids.extend(selector) + else: + request.deck_id = selector return self._backend.export_anki_package(request) # Object helpers