diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2022-10-22 10:49:19 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:52 +0100 |
commit | c783a78f7702fa45fc41b8048aad5c249cdcad1f (patch) | |
tree | 91a1bdaa3753879799fe9856c80b443b8ce3135e | |
parent | a3038c176869e1d916efef732ef229f40becdbe4 (diff) | |
download | wee-slack-c783a78f7702fa45fc41b8048aad5c249cdcad1f.tar.gz |
Support config options with a Literal Union type
-rw-r--r-- | slack.py | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -15,6 +15,7 @@ from typing import ( Tuple, TypeVar, Union, + cast, ) from typing import Awaitable, Coroutine from urllib.parse import urlencode @@ -143,7 +144,7 @@ class WeeChatSection: ) -WeeChatOptionType = TypeVar("WeeChatOptionType", bool, int, WeeChatColor, str) +WeeChatOptionType = TypeVar("WeeChatOptionType", bound=int | str) @dataclass @@ -171,13 +172,13 @@ class WeeChatOption(Generic[WeeChatOptionType]): option_pointer = self._pointer if isinstance(self.default_value, bool): - return weechat.config_boolean(option_pointer) == 1 + return cast(WeeChatOptionType, weechat.config_boolean(option_pointer) == 1) if isinstance(self.default_value, int): - return weechat.config_integer(option_pointer) + return cast(WeeChatOptionType, weechat.config_integer(option_pointer)) if isinstance(self.default_value, WeeChatColor): color = weechat.config_color(option_pointer) - return WeeChatColor(color) - return weechat.config_string(option_pointer) + return cast(WeeChatOptionType, WeeChatColor(color)) + return cast(WeeChatOptionType, weechat.config_string(option_pointer)) @property def _weechat_type(self) -> str: |