1
1
from __future__ import annotations
2
2
3
3
from abc import ABC
4
- from typing import Annotated , Any , Generic , Literal , NamedTuple , Optional , Union
4
+ from typing import Annotated , Generic , Literal , NamedTuple , Optional , Union
5
5
6
- from pydantic import Field
6
+ from pydantic import Field , JsonValue
7
7
from typing_extensions import TypedDict , TypeVar
8
8
9
9
from streamdeck .models .events .base import ConfiguredBaseModel
@@ -28,8 +28,11 @@ class DeviceSpecificEventMixin:
28
28
## Payload models and metadata used by multiple event models.
29
29
30
30
31
- PluginDefinedData = dict [str , Any ]
32
- """Data of arbitrary structure that is defined in and relevant to the plugin."""
31
+ PluginDefinedData = dict [str , JsonValue ]
32
+ """Data of arbitrary structure that is defined in and relevant to the plugin.
33
+
34
+ The root of the data structure will always be a dict of string keys, while the values can be any JSON-compatible type.
35
+ """
33
36
34
37
35
38
EncoderControllerType = Literal ["Encoder" ]
@@ -116,10 +119,14 @@ class MultiActionPayloadMixin:
116
119
"""Indicates that this event is part of a multi-action."""
117
120
118
121
122
+ # These need to be covariant, as the Mixin classes are never meant to be instantiated themselves, only inherited from.
123
+ SingleActionPayload_co = TypeVar ("SingleActionPayload_co" , bound = SingleActionPayloadMixin , covariant = True )
124
+ MultiActionPayload_co = TypeVar ("MultiActionPayload_co" , bound = MultiActionPayloadMixin , covariant = True )
125
+
119
126
CardinalityDiscriminated = Annotated [
120
127
Union [ # noqa: UP007
121
- TypeVar ( "S" , bound = SingleActionPayloadMixin ) ,
122
- TypeVar ( "M" , bound = MultiActionPayloadMixin ) ,
128
+ SingleActionPayload_co ,
129
+ MultiActionPayload_co ,
123
130
],
124
131
Field (discriminator = "is_in_multi_action" ),
125
132
]
0 commit comments