typed-event 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+ .coverage
12
+ uv.lock
13
+ .vscode/settings.json
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,7 @@
1
+ Copyright 2026 J. Löhnert
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.4
2
+ Name: typed-event
3
+ Version: 1.0.0
4
+ Summary: Strongly-typed event decorator
5
+ Project-URL: Homepage, http://github.com/loehnertj/typed_event
6
+ Project-URL: Repository, http://github.com/loehnertj/typed_event
7
+ Author-email: Johannes Loehnert <loehnert.kde@gmx.de>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.13
18
+ Description-Content-Type: text/markdown
19
+
20
+ # typed-event
21
+
22
+ Strongly-typed events for Python via an `@event` decorator.
23
+
24
+ `typed-event` lets you define an event from a function/method prototype, then
25
+ subscribe listeners with `+=` and unsubscribe with `-=`.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install typed-event
31
+ ```
32
+
33
+ ## Quick start
34
+
35
+ ### Module-level event
36
+
37
+ ```python
38
+ from typed_event import event
39
+
40
+
41
+ @event
42
+ def counter_changed(new_value: int, /):
43
+ """Fired whenever the counter changes."""
44
+
45
+
46
+ def print_value(new_value: int):
47
+ print("new value:", new_value)
48
+
49
+
50
+ counter_changed += print_value
51
+ counter_changed(42)
52
+ counter_changed -= print_value
53
+ ```
54
+
55
+ Note that by default, `@event` requires you to make it explicit whether values
56
+ are passed positionally or as keyword.
57
+
58
+ ### Class events
59
+
60
+ ```python
61
+ from typed_event import event
62
+
63
+
64
+ class Counter:
65
+ def __init__(self):
66
+ self._value = 0
67
+
68
+ @event
69
+ def changed(value: int, /):
70
+ """Fired when value changes."""
71
+
72
+ def set_value(self, value: int):
73
+ self._value = value
74
+ self.changed(value) # fire the event
75
+
76
+
77
+ c1 = Counter()
78
+ c2 = Counter()
79
+
80
+ def on_c1(value: int):
81
+ print("c1:", value)
82
+
83
+ def on_c2(value: int):
84
+ print("c2:", value)
85
+
86
+ c1.changed += on_c1
87
+ c2.changed += on_c2
88
+
89
+ c1.set_value(1) # prints "c1: 1"
90
+ c2.set_value(2) # prints "c2: 2"
91
+ ```
92
+
93
+ Each instance gets its own bound event with its own listener list.
94
+
95
+ ## Defining event prototypes
96
+
97
+ Prototype restrictions:
98
+
99
+ - No default argument values.
100
+ - No `*args` / `**kwargs` in the event prototype.
101
+ - Strict mode (enabled by default) requires parameters to be explicitly positional-only (`/`) or keyword-only (`*`). Opt-out by using `@event(strict=False)`.
102
+
103
+ Example with explicit keyword-only parameters:
104
+
105
+ ```python
106
+ from typed_event import event
107
+
108
+
109
+ @event
110
+ def changed(*, a: int, b: int):
111
+ pass
112
+
113
+
114
+ changed(a=1, b=2) # ok
115
+ # changed(1, 2) # TypeError
116
+ ```
117
+
118
+ **Notes:**
119
+
120
+ - Listener signatures are not validated at subscription time; a mismatch only fails when invoked.
121
+ - Type annotations are **not** runtime-enforced — the name refers to static typing support, not runtime checks.
122
+
123
+ ## Cancellation
124
+
125
+ Raise `CancelEvent` in a listener to stop processing remaining listeners:
126
+
127
+ ```python
128
+ from typed_event import event, CancelEvent
129
+
130
+
131
+ @event
132
+ def changed(value: int, /):
133
+ pass
134
+
135
+
136
+ def first(value: int):
137
+ raise CancelEvent()
138
+
139
+
140
+ def second(value: int):
141
+ print("never called")
142
+
143
+
144
+ changed += first
145
+ changed += second
146
+ changed(1)
147
+ ```
148
+
149
+ ## Exception handling policy
150
+
151
+ Set via `@event(exceptions=...)`:
152
+
153
+ - `"default"` (default): passes exceptions to `sys.excepthook`.
154
+ - `"log"`: logs exceptions via `logging.exception`.
155
+ - `"raise"`: re-raises immediately and stops further listeners. I.e. no "handling" at all.
156
+ - `"group"`: runs all listeners, then raises `ExceptionGroup` if any failed.
157
+
158
+ `CancelEvent` is handled separately and is never treated as an error.
159
+
160
+ ## Return values
161
+
162
+ At most one non-`None` return value is allowed across prototype + listeners.
163
+ If multiple handlers return a value, a `RuntimeError` is raised.
164
+
165
+ ## Changing event settings on module / project level
166
+
167
+ To define many events with changed settings (e.g. different default for `exception`), make an alias decorator like so:
168
+
169
+ ```
170
+ from typed_event import event
171
+ my_event = event(strict=False, exceptions="log")
172
+
173
+ @my_event
174
+ def event1(): ...
175
+
176
+ @my_event
177
+ def event2(): ...
178
+ ```
179
+
180
+ To apply project-wide, define the alias in a helper module and import from there.
181
+
182
+ ## Changelog
183
+
184
+ ### Version 1.0 (23.03.2026)
185
+
186
+ First release of the library as standalone project. Previously it was part of [ASCII
187
+ Designer](https://github.com/loehnertj/ascii_designer).
188
+
189
+ Minor changes happened (strict mode as default, using sys.excepthook instead of
190
+ print). Besides that, comprehensive testing and documentation was added.
191
+
192
+ ## License
193
+
194
+ Provided under [MIT license](LICENSE).
@@ -0,0 +1,175 @@
1
+ # typed-event
2
+
3
+ Strongly-typed events for Python via an `@event` decorator.
4
+
5
+ `typed-event` lets you define an event from a function/method prototype, then
6
+ subscribe listeners with `+=` and unsubscribe with `-=`.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install typed-event
12
+ ```
13
+
14
+ ## Quick start
15
+
16
+ ### Module-level event
17
+
18
+ ```python
19
+ from typed_event import event
20
+
21
+
22
+ @event
23
+ def counter_changed(new_value: int, /):
24
+ """Fired whenever the counter changes."""
25
+
26
+
27
+ def print_value(new_value: int):
28
+ print("new value:", new_value)
29
+
30
+
31
+ counter_changed += print_value
32
+ counter_changed(42)
33
+ counter_changed -= print_value
34
+ ```
35
+
36
+ Note that by default, `@event` requires you to make it explicit whether values
37
+ are passed positionally or as keyword.
38
+
39
+ ### Class events
40
+
41
+ ```python
42
+ from typed_event import event
43
+
44
+
45
+ class Counter:
46
+ def __init__(self):
47
+ self._value = 0
48
+
49
+ @event
50
+ def changed(value: int, /):
51
+ """Fired when value changes."""
52
+
53
+ def set_value(self, value: int):
54
+ self._value = value
55
+ self.changed(value) # fire the event
56
+
57
+
58
+ c1 = Counter()
59
+ c2 = Counter()
60
+
61
+ def on_c1(value: int):
62
+ print("c1:", value)
63
+
64
+ def on_c2(value: int):
65
+ print("c2:", value)
66
+
67
+ c1.changed += on_c1
68
+ c2.changed += on_c2
69
+
70
+ c1.set_value(1) # prints "c1: 1"
71
+ c2.set_value(2) # prints "c2: 2"
72
+ ```
73
+
74
+ Each instance gets its own bound event with its own listener list.
75
+
76
+ ## Defining event prototypes
77
+
78
+ Prototype restrictions:
79
+
80
+ - No default argument values.
81
+ - No `*args` / `**kwargs` in the event prototype.
82
+ - Strict mode (enabled by default) requires parameters to be explicitly positional-only (`/`) or keyword-only (`*`). Opt-out by using `@event(strict=False)`.
83
+
84
+ Example with explicit keyword-only parameters:
85
+
86
+ ```python
87
+ from typed_event import event
88
+
89
+
90
+ @event
91
+ def changed(*, a: int, b: int):
92
+ pass
93
+
94
+
95
+ changed(a=1, b=2) # ok
96
+ # changed(1, 2) # TypeError
97
+ ```
98
+
99
+ **Notes:**
100
+
101
+ - Listener signatures are not validated at subscription time; a mismatch only fails when invoked.
102
+ - Type annotations are **not** runtime-enforced — the name refers to static typing support, not runtime checks.
103
+
104
+ ## Cancellation
105
+
106
+ Raise `CancelEvent` in a listener to stop processing remaining listeners:
107
+
108
+ ```python
109
+ from typed_event import event, CancelEvent
110
+
111
+
112
+ @event
113
+ def changed(value: int, /):
114
+ pass
115
+
116
+
117
+ def first(value: int):
118
+ raise CancelEvent()
119
+
120
+
121
+ def second(value: int):
122
+ print("never called")
123
+
124
+
125
+ changed += first
126
+ changed += second
127
+ changed(1)
128
+ ```
129
+
130
+ ## Exception handling policy
131
+
132
+ Set via `@event(exceptions=...)`:
133
+
134
+ - `"default"` (default): passes exceptions to `sys.excepthook`.
135
+ - `"log"`: logs exceptions via `logging.exception`.
136
+ - `"raise"`: re-raises immediately and stops further listeners. I.e. no "handling" at all.
137
+ - `"group"`: runs all listeners, then raises `ExceptionGroup` if any failed.
138
+
139
+ `CancelEvent` is handled separately and is never treated as an error.
140
+
141
+ ## Return values
142
+
143
+ At most one non-`None` return value is allowed across prototype + listeners.
144
+ If multiple handlers return a value, a `RuntimeError` is raised.
145
+
146
+ ## Changing event settings on module / project level
147
+
148
+ To define many events with changed settings (e.g. different default for `exception`), make an alias decorator like so:
149
+
150
+ ```
151
+ from typed_event import event
152
+ my_event = event(strict=False, exceptions="log")
153
+
154
+ @my_event
155
+ def event1(): ...
156
+
157
+ @my_event
158
+ def event2(): ...
159
+ ```
160
+
161
+ To apply project-wide, define the alias in a helper module and import from there.
162
+
163
+ ## Changelog
164
+
165
+ ### Version 1.0 (23.03.2026)
166
+
167
+ First release of the library as standalone project. Previously it was part of [ASCII
168
+ Designer](https://github.com/loehnertj/ascii_designer).
169
+
170
+ Minor changes happened (strict mode as default, using sys.excepthook instead of
171
+ print). Besides that, comprehensive testing and documentation was added.
172
+
173
+ ## License
174
+
175
+ Provided under [MIT license](LICENSE).
@@ -0,0 +1,2 @@
1
+ # Created by coverage.py
2
+ *
@@ -0,0 +1,141 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <title>Coverage report</title>
6
+ <link rel="icon" sizes="32x32" href="favicon_32_cb_c827f16f.png">
7
+ <link rel="stylesheet" href="style_cb_9ff733b0.css" type="text/css">
8
+ <script src="coverage_html_cb_dd2e7eb5.js" defer></script>
9
+ </head>
10
+ <body class="indexfile">
11
+ <header>
12
+ <div class="content">
13
+ <h1>Coverage report:
14
+ <span class="pc_cov">100%</span>
15
+ </h1>
16
+ <aside id="help_panel_wrapper">
17
+ <input id="help_panel_state" type="checkbox">
18
+ <label for="help_panel_state">
19
+ <img id="keyboard_icon" src="keybd_closed_cb_900cfef5.png" alt="Show/hide keyboard shortcuts">
20
+ </label>
21
+ <div id="help_panel">
22
+ <p class="legend">Shortcuts on this page</p>
23
+ <div class="keyhelp">
24
+ <p>
25
+ <kbd>f</kbd>
26
+ <kbd>n</kbd>
27
+ <kbd>s</kbd>
28
+ <kbd>m</kbd>
29
+ <kbd>x</kbd>
30
+ <kbd>c</kbd>
31
+ &nbsp; change column sorting
32
+ </p>
33
+ <p>
34
+ <kbd>[</kbd>
35
+ <kbd>]</kbd>
36
+ &nbsp; prev/next file
37
+ </p>
38
+ <p>
39
+ <kbd>?</kbd> &nbsp; show/hide this help
40
+ </p>
41
+ </div>
42
+ </div>
43
+ </aside>
44
+ <form id="filter_container">
45
+ <input id="filter" type="text" value="" placeholder="filter...">
46
+ <div>
47
+ <input id="hide100" type="checkbox" >
48
+ <label for="hide100">hide covered</label>
49
+ </div>
50
+ </form>
51
+ <h2>
52
+ <a class="button" href="index.html">Files</a>
53
+ <a class="button" href="function_index.html">Functions</a>
54
+ <a class="button current">Classes</a>
55
+ </h2>
56
+ <p class="text">
57
+ <a class="nav" href="https://coverage.readthedocs.io/en/7.13.5">coverage.py v7.13.5</a>,
58
+ created at 2026-03-20 21:27 +0100
59
+ </p>
60
+ </div>
61
+ </header>
62
+ <main id="index">
63
+ <table class="index" data-sortable>
64
+ <thead>
65
+ <tr class="tablehead" title="Click to sort">
66
+ <th id="file" class="name" aria-sort="none" data-shortcut="f">File<span class="arrows"></span></th>
67
+ <th id="region" class="name" aria-sort="none" data-default-sort-order="ascending" data-shortcut="n">class<span class="arrows"></span></th>
68
+ <th class="spacer">&nbsp;</th>
69
+ <th id="statements" aria-sort="none" data-default-sort-order="descending" data-shortcut="s">statements<span class="arrows"></span></th>
70
+ <th id="missing" aria-sort="none" data-default-sort-order="descending" data-shortcut="m">missing<span class="arrows"></span></th>
71
+ <th id="excluded" aria-sort="none" data-default-sort-order="descending" data-shortcut="x">excluded<span class="arrows"></span></th>
72
+ <th class="spacer">&nbsp;</th>
73
+ <th id="coverage" aria-sort="none" data-shortcut="c">coverage<span class="arrows"></span></th>
74
+ </tr>
75
+ </thead>
76
+ <tbody>
77
+ <tr class="region">
78
+ <td class="name"><a href="z_145eef247bfb46b6_typed_event_py.html#t43">src&#8201;/&#8201;typed_event.py</a></td>
79
+ <td class="name"><a href="z_145eef247bfb46b6_typed_event_py.html#t43"><data value='CancelEvent'>CancelEvent</data></a></td>
80
+ <td class="spacer">&nbsp;</td>
81
+ <td>0</td>
82
+ <td>0</td>
83
+ <td>0</td>
84
+ <td class="spacer">&nbsp;</td>
85
+ <td data-ratio="0 0">100%</td>
86
+ </tr>
87
+ <tr class="region">
88
+ <td class="name"><a href="z_145eef247bfb46b6_typed_event_py.html#t47">src&#8201;/&#8201;typed_event.py</a></td>
89
+ <td class="name"><a href="z_145eef247bfb46b6_typed_event_py.html#t47"><data value='Event'>Event</data></a></td>
90
+ <td class="spacer">&nbsp;</td>
91
+ <td>62</td>
92
+ <td>0</td>
93
+ <td>0</td>
94
+ <td class="spacer">&nbsp;</td>
95
+ <td data-ratio="62 62">100%</td>
96
+ </tr>
97
+ <tr class="region">
98
+ <td class="name"><a href="z_145eef247bfb46b6_typed_event_py.html">src&#8201;/&#8201;typed_event.py</a></td>
99
+ <td class="name"><a href="z_145eef247bfb46b6_typed_event_py.html"><data value=''><span class='no-noun'>(no class)</span></data></a></td>
100
+ <td class="spacer">&nbsp;</td>
101
+ <td>26</td>
102
+ <td>0</td>
103
+ <td>20</td>
104
+ <td class="spacer">&nbsp;</td>
105
+ <td data-ratio="26 26">100%</td>
106
+ </tr>
107
+ </tbody>
108
+ <tfoot>
109
+ <tr class="total">
110
+ <td class="name">Total</td>
111
+ <td class="name">&nbsp;</td>
112
+ <td class="spacer">&nbsp;</td>
113
+ <td>88</td>
114
+ <td>0</td>
115
+ <td>20</td>
116
+ <td class="spacer">&nbsp;</td>
117
+ <td data-ratio="88 88">100%</td>
118
+ </tr>
119
+ </tfoot>
120
+ </table>
121
+ <p id="no_rows">
122
+ No items found using the specified filter.
123
+ </p>
124
+ </main>
125
+ <footer>
126
+ <div class="content">
127
+ <p>
128
+ <a class="nav" href="https://coverage.readthedocs.io/en/7.13.5">coverage.py v7.13.5</a>,
129
+ created at 2026-03-20 21:27 +0100
130
+ </p>
131
+ </div>
132
+ <aside class="hidden">
133
+ <a id="prevFileLink" class="nav" href=""></a>
134
+ <a id="nextFileLink" class="nav" href=""></a>
135
+ <button type="button" class="button_prev_file" data-shortcut="["></button>
136
+ <button type="button" class="button_next_file" data-shortcut="]"></button>
137
+ <button type="button" class="button_show_hide_help" data-shortcut="?"></button>
138
+ </aside>
139
+ </footer>
140
+ </body>
141
+ </html>