aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2022-10-22 10:49:19 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:52 +0100
commitc783a78f7702fa45fc41b8048aad5c249cdcad1f (patch)
tree91a1bdaa3753879799fe9856c80b443b8ce3135e
parenta3038c176869e1d916efef732ef229f40becdbe4 (diff)
downloadwee-slack-c783a78f7702fa45fc41b8048aad5c249cdcad1f.tar.gz
Support config options with a Literal Union type
-rw-r--r--slack.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/slack.py b/slack.py
index 2e7e2cd..4727214 100644
--- a/slack.py
+++ b/slack.py
@@ -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: