Skip to content

Commit 9ccbac7

Browse files
committed
minor clean up of handing ellipsis
1 parent 926b144 commit 9ccbac7

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

options.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ def __init__(self) -> None:
104104
raise NotImplementedError
105105

106106
def _to_json(self) -> J:
107-
"""
108-
Turns this option into a JSON value.
109-
110-
Returns:
111-
This option's JSON representation.
112-
"""
113107
return self.value
114108

115109
def __post_init__(self) -> None:
@@ -364,12 +358,6 @@ class ButtonOption(BaseOption):
364358
on_press: Callable[[Self], None] | None = None
365359

366360
def _to_json(self) -> EllipsisType:
367-
"""
368-
A dummy method to adhere to BaseOption interface, while indicating no JSON representation.
369-
370-
Returns:
371-
Ellipsis, indicating that ButtonOption cannot be represented as a value.
372-
"""
373361
return ...
374362

375363
def _from_json(self, value: JSON) -> None:
@@ -479,12 +467,11 @@ class GroupedOption(BaseOption):
479467
children: Sequence[BaseOption]
480468

481469
def _to_json(self) -> JSON:
482-
grouped_option_dict: Mapping[str, JSON] = {}
483-
for option in self.children:
484-
if option._to_json() == ...:
485-
continue
486-
grouped_option_dict[option.identifier] = cast(JSON, option._to_json())
487-
return grouped_option_dict
470+
return {
471+
option.identifier: child_json
472+
for option in self.children
473+
if (child_json := option._to_json()) is not ...
474+
}
488475

489476
def _from_json(self, value: JSON) -> None:
490477
if isinstance(value, Mapping):
@@ -523,12 +510,11 @@ class NestedOption(BaseOption):
523510
children: Sequence[BaseOption]
524511

525512
def _to_json(self) -> JSON:
526-
grouped_option_dict: Mapping[str, JSON] = {}
527-
for option in self.children:
528-
if option._to_json() == ...:
529-
continue
530-
grouped_option_dict[option.identifier] = cast(JSON, option._to_json())
531-
return grouped_option_dict
513+
return {
514+
option.identifier: child_json
515+
for option in self.children
516+
if (child_json := option._to_json()) is not ...
517+
}
532518

533519
def _from_json(self, value: JSON) -> None:
534520
if isinstance(value, Mapping):

settings.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import json
44
from collections.abc import Mapping, Sequence
5-
from typing import TYPE_CHECKING, TypedDict, cast
5+
from typing import TYPE_CHECKING, TypedDict
66

77
from . import MODS_DIR
88

@@ -81,14 +81,12 @@ def create_options_dict(options: Sequence[BaseOption]) -> dict[str, JSON]:
8181
Returns:
8282
The options' values in dict form.
8383
"""
84-
settings: dict[str, JSON] = {
85-
option.identifier: cast(JSON, option._to_json()) # type: ignore
84+
return {
85+
option.identifier: child_json
8686
for option in options
87-
if option._to_json() != ... # type: ignore
87+
if (child_json := option._to_json()) is not ... # pyright: ignore[reportPrivateUsage]
8888
}
8989

90-
return settings
91-
9290

9391
def default_save_mod_settings(self: Mod) -> None:
9492
"""Default implementation for Mod.save_settings."""

0 commit comments

Comments
 (0)