Skip to content

Commit 8efe19d

Browse files
committed
Remove generic alias type alias from EventBase annotations
1 parent f76fd22 commit 8efe19d

23 files changed

Lines changed: 62 additions & 90 deletions

streamdeck/actions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _wrapper(func: EventHandlerFunc[TEvent_contra]) -> EventHandlerFunc[TEvent_c
4949

5050
return _wrapper
5151

52-
def get_event_handlers(self, event_name: EventNameStr, /) -> Generator[EventHandlerFunc[EventBase[LiteralStrGenericAlias]], None, None]:
52+
def get_event_handlers(self, event_name: EventNameStr, /) -> Generator[EventHandlerFunc[EventBase], None, None]:
5353
"""Get all event handlers for a specific event.
5454
5555
Args:
@@ -66,14 +66,15 @@ def get_event_handlers(self, event_name: EventNameStr, /) -> Generator[EventHand
6666

6767
yield from self._events[event_name]
6868

69-
def get_registered_event_names(self) -> list[str]:
69+
def get_registered_event_names(self) -> list[EventNameStr]:
7070
"""Get all event names for which event handlers are registered.
7171
7272
Returns:
7373
list[str]: The list of event names for which event handlers are registered.
7474
"""
7575
return list(self._events.keys())
7676

77+
7778
class GlobalAction(ActionBase):
7879
"""Represents an action that is performed at the plugin level, meaning it isn't associated with a specific device or action."""
7980

@@ -111,7 +112,7 @@ def register(self, action: ActionBase) -> None:
111112
"""
112113
self._plugin_actions.append(action)
113114

114-
def get_action_handlers(self, event_name: EventNameStr, event_action_uuid: str | None = None) -> Generator[EventHandlerFunc[EventBase[LiteralStrGenericAlias]], None, None]:
115+
def get_action_handlers(self, event_name: EventNameStr, event_action_uuid: str | None = None) -> Generator[EventHandlerFunc[EventBase], None, None]:
115116
"""Get all event handlers for a specific event from all registered actions.
116117
117118
Args:

streamdeck/event_listener.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from typing_extensions import TypeIs
1515

1616
from streamdeck.models.events import EventBase
17-
from streamdeck.models.events.base import LiteralStrGenericAlias
1817

1918

2019

@@ -120,7 +119,7 @@ class EventListener(ABC):
120119
Event listeners are classes that listen for events and simply yield them as they come.
121120
The EventListenerManager will handle the threading and pushing the events yielded into a shared queue.
122121
"""
123-
event_models: ClassVar[list[type[EventBase[LiteralStrGenericAlias]]]]
122+
event_models: ClassVar[list[type[EventBase]]]
124123
"""A list of event models that the listener can yield. Read in by the PluginManager to model the incoming event data off of.
125124
126125
The plugin-developer must define this list in their subclass.

streamdeck/manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from typing import Any, Literal
2727

2828
from streamdeck.models.events import EventBase
29-
from streamdeck.models.events.base import LiteralStrGenericAlias
3029

3130

3231
# TODO: Fix this up to push to a log in the apropos directory and filename.
@@ -121,7 +120,7 @@ def _inject_command_sender(self, handler: EventHandlerFunc[TEvent_contra], comma
121120

122121
return handler
123122

124-
def _stream_event_data(self) -> Generator[EventBase[LiteralStrGenericAlias], None, None]:
123+
def _stream_event_data(self) -> Generator[EventBase, None, None]:
125124
"""Stream event data from the event listeners.
126125
127126
Validate and model the incoming event data before yielding it.
@@ -131,7 +130,7 @@ def _stream_event_data(self) -> Generator[EventBase[LiteralStrGenericAlias], Non
131130
"""
132131
for message in self._event_listener_manager.event_stream():
133132
try:
134-
data: EventBase[LiteralStrGenericAlias] = self._event_adapter.validate_json(message)
133+
data: EventBase = self._event_adapter.validate_json(message)
135134
except ValidationError:
136135
logger.exception("Error modeling event data.")
137136
continue

streamdeck/models/events/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@
3131
if TYPE_CHECKING:
3232
from typing import Final
3333

34-
from streamdeck.models.events.base import LiteralStrGenericAlias
3534

36-
37-
DEFAULT_EVENT_MODELS: Final[list[type[EventBase[LiteralStrGenericAlias]]]] = [
35+
DEFAULT_EVENT_MODELS: Final[list[type[EventBase]]] = [
3836
ApplicationDidLaunch,
3937
ApplicationDidTerminate,
4038
DeviceDidConnect,

streamdeck/models/events/adapter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99

1010
if TYPE_CHECKING:
11-
from streamdeck.models.events.base import EventBase, LiteralStrGenericAlias
11+
from streamdeck.models.events.base import EventBase
1212

1313

1414
class EventAdapter:
1515
"""TypeAdapter-encompassing class for handling and extending available event models."""
1616
def __init__(self) -> None:
17-
self._models: list[type[EventBase[LiteralStrGenericAlias]]] = []
18-
self._type_adapter: TypeAdapter[EventBase[LiteralStrGenericAlias]] | None = None
17+
self._models: list[type[EventBase]] = []
18+
self._type_adapter: TypeAdapter[EventBase] | None = None
1919

2020
self._event_names: set[str] = set()
2121
"""A set of all event names that have been registered with the adapter.
@@ -25,7 +25,7 @@ def __init__(self) -> None:
2525
for model in DEFAULT_EVENT_MODELS:
2626
self.add_model(model)
2727

28-
def add_model(self, model: type[EventBase[LiteralStrGenericAlias]]) -> None:
28+
def add_model(self, model: type[EventBase]) -> None:
2929
"""Add a model to the adapter, and add the event name of the model to the set of registered event names."""
3030
self._models.append(model)
3131
# Models can have multiple event names defined in the Literal args of the event field,
@@ -37,7 +37,7 @@ def event_name_exists(self, event_name: str) -> bool:
3737
return event_name in self._event_names
3838

3939
@property
40-
def type_adapter(self) -> TypeAdapter[EventBase[LiteralStrGenericAlias]]:
40+
def type_adapter(self) -> TypeAdapter[EventBase]:
4141
"""Get the TypeAdapter instance for the event models."""
4242
if self._type_adapter is None:
4343
self._type_adapter = TypeAdapter(
@@ -49,7 +49,7 @@ def type_adapter(self) -> TypeAdapter[EventBase[LiteralStrGenericAlias]]:
4949

5050
return self._type_adapter
5151

52-
def validate_json(self, data: str | bytes) -> EventBase[LiteralStrGenericAlias]:
52+
def validate_json(self, data: str | bytes) -> EventBase:
5353
"""Validate a JSON string or bytes object as an event model."""
5454
return self.type_adapter.validate_json(data)
5555

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import Literal
4-
53
from streamdeck.models.events.base import ConfiguredBaseModel, EventBase
64

75

@@ -11,13 +9,13 @@ class ApplicationPayload(ConfiguredBaseModel):
119
"""Name of the application that triggered the event."""
1210

1311

14-
class ApplicationDidLaunch(EventBase[Literal["applicationDidLaunch"]]):
12+
class ApplicationDidLaunch(EventBase["applicationDidLaunch"]):
1513
"""Occurs when a monitored application is launched."""
1614
payload: ApplicationPayload
1715
"""Payload containing the name of the application that triggered the event."""
1816

1917

20-
class ApplicationDidTerminate(EventBase[Literal["applicationDidTerminate"]]):
18+
class ApplicationDidTerminate(EventBase["applicationDidTerminate"]):
2119
"""Occurs when a monitored application terminates."""
2220
payload: ApplicationPayload
2321
"""Payload containing the name of the application that triggered the event."""

streamdeck/models/events/deep_link.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Literal
2-
31
from streamdeck.models.events.base import ConfiguredBaseModel, EventBase
42

53

@@ -9,7 +7,7 @@ class DeepLinkPayload(ConfiguredBaseModel):
97
"""The deep-link URL, with the prefix omitted."""
108

119

12-
class DidReceiveDeepLink(EventBase[Literal["didReceiveDeepLink"]]):
10+
class DidReceiveDeepLink(EventBase["didReceiveDeepLink"]):
1311
"""Occurs when Stream Deck receives a deep-link message intended for the plugin.
1412
1513
The message is re-routed to the plugin, and provided as part of the payload.

streamdeck/models/events/devices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def __repr__(self) -> str:
7878
return f"DeviceInfo(name={self.name}, type={self.type}, size={self.size})"
7979

8080

81-
class DeviceDidConnect(EventBase[Literal["deviceDidConnect"]], DeviceSpecificEventMixin):
81+
class DeviceDidConnect(EventBase["deviceDidConnect"], DeviceSpecificEventMixin):
8282
"""Occurs when a Stream Deck device is connected."""
8383
device_info: Annotated[DeviceInfo, Field(alias="deviceInfo")]
8484
"""Information about the newly connected device."""
8585

8686

87-
class DeviceDidDisconnect(EventBase[Literal["deviceDidDisconnect"]], DeviceSpecificEventMixin):
87+
class DeviceDidDisconnect(EventBase["deviceDidDisconnect"], DeviceSpecificEventMixin):
8888
"""Occurs when a Stream Deck device is disconnected."""

streamdeck/models/events/dials.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import Literal
4-
53
from streamdeck.models.events.base import EventBase
64
from streamdeck.models.events.common import (
75
BasePayload,
@@ -28,19 +26,19 @@ class DialRotatePayload(EncoderPayload):
2826

2927
## Event models for DialDown, DialRotate, and DialUp events
3028

31-
class DialDown(EventBase[Literal["dialDown"]], ContextualEventMixin, DeviceSpecificEventMixin):
29+
class DialDown(EventBase["dialDown"], ContextualEventMixin, DeviceSpecificEventMixin):
3230
"""Occurs when the user presses a dial (Stream Deck +)."""
3331
payload: EncoderPayload
3432
"""Contextualized information for this event."""
3533

3634

37-
class DialRotate(EventBase[Literal["dialRotate"]], ContextualEventMixin, DeviceSpecificEventMixin):
35+
class DialRotate(EventBase["dialRotate"], ContextualEventMixin, DeviceSpecificEventMixin):
3836
"""Occurs when the user rotates a dial (Stream Deck +)."""
3937
payload: DialRotatePayload
4038
"""Contextualized information for this event."""
4139

4240

43-
class DialUp(EventBase[Literal["dialUp"]], ContextualEventMixin, DeviceSpecificEventMixin):
41+
class DialUp(EventBase["dialUp"], ContextualEventMixin, DeviceSpecificEventMixin):
4442
"""Occurs when the user releases a pressed dial (Stream Deck +)."""
4543
payload: EncoderPayload
4644
"""Contextualized information for this event."""

streamdeck/models/events/keys.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Annotated, Literal
3+
from typing import Annotated
44

55
from pydantic import Field
66

@@ -48,13 +48,13 @@ class MultiActionKeyGesturePayload(
4848

4949
## Event models for KeyDown and KeyUp events
5050

51-
class KeyDown(EventBase[Literal["keyDown"]], ContextualEventMixin, DeviceSpecificEventMixin):
51+
class KeyDown(EventBase["keyDown"], ContextualEventMixin, DeviceSpecificEventMixin):
5252
"""Occurs when the user presses a action down."""
5353
payload: CardinalityDiscriminated[SingleActionKeyGesturePayload, MultiActionKeyGesturePayload]
5454
"""Contextualized information for this event."""
5555

5656

57-
class KeyUp(EventBase[Literal["keyUp"]], ContextualEventMixin, DeviceSpecificEventMixin):
57+
class KeyUp(EventBase["keyUp"], ContextualEventMixin, DeviceSpecificEventMixin):
5858
"""Occurs when the user releases a pressed action."""
5959
payload: CardinalityDiscriminated[SingleActionKeyGesturePayload, MultiActionKeyGesturePayload]
6060
"""Contextualized information for this event."""

0 commit comments

Comments
 (0)