mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
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.
This commit is contained in:
parent
070d3045eb
commit
0e9a8e18c1
2 changed files with 7 additions and 7 deletions
|
@ -22,6 +22,7 @@ ignored-classes=
|
||||||
CustomStudyRequest,
|
CustomStudyRequest,
|
||||||
Cram,
|
Cram,
|
||||||
ScheduleCardsAsNewRequest,
|
ScheduleCardsAsNewRequest,
|
||||||
|
ExportAnkiPackageRequest,
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
output-format=colorized
|
output-format=colorized
|
||||||
|
|
|
@ -379,19 +379,18 @@ class Collection(DeprecatedNamesMixin):
|
||||||
with_scheduling: bool,
|
with_scheduling: bool,
|
||||||
with_media: bool,
|
with_media: bool,
|
||||||
) -> int:
|
) -> 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(
|
request = ExportAnkiPackageRequest(
|
||||||
out_path=out_path,
|
out_path=out_path,
|
||||||
with_scheduling=with_scheduling,
|
with_scheduling=with_scheduling,
|
||||||
with_media=with_media,
|
with_media=with_media,
|
||||||
legacy=True,
|
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)
|
return self._backend.export_anki_package(request)
|
||||||
|
|
||||||
# Object helpers
|
# Object helpers
|
||||||
|
|
Loading…
Reference in a new issue