cutienator 0.0.1.dev0__py3-none-any.whl
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.
- cutienator/__init__.py +44 -0
- cutienator/_cpp_addr.py +84 -0
- cutienator/_cpp_box.py +23 -0
- cutienator/_cute_load_hook.py +159 -0
- cutienator/_cute_mixin.py +166 -0
- cutienator/_cute_overload.py +285 -0
- cutienator/_cute_space.py +727 -0
- cutienator/_header_descriptor.py +4 -0
- cutienator/_meta_cute.py +444 -0
- cutienator/_q_binding_storage.py +101 -0
- cutienator/_q_event.py +185 -0
- cutienator/_q_meta_object.py +118 -0
- cutienator/_q_object.py +582 -0
- cutienator/_q_thread.py +106 -0
- cutienator/_q_widget.py +80 -0
- cutienator/_ugly.py +296 -0
- cutienator/_wait.py +303 -0
- cutienator/_waiting_overload.py +261 -0
- cutienator/example/__init__.py +21 -0
- cutienator/example/__main__.py +67 -0
- cutienator/example/_calls.py +107 -0
- cutienator/occult/__init__.py +27 -0
- cutienator/occult/__main__.py +50 -0
- cutienator/occult/_base_meta_ugly.py +29 -0
- cutienator/occult/_build.py +561 -0
- cutienator/occult/_cognito_warning.py +35 -0
- cutienator/occult/_declaration.py +572 -0
- cutienator/occult/_header.py +710 -0
- cutienator/occult/_ritual.py +19 -0
- cutienator/occult/_rituals.py +594 -0
- cutienator/occult/_shared_object.py +292 -0
- cutienator/occult/_symbol.py +162 -0
- cutienator/occult/rituals/q_event.cpp +70 -0
- cutienator/occult/rituals/q_meta_object.cpp +173 -0
- cutienator/occult/rituals/q_object.cpp +178 -0
- cutienator/trial/__init__.py +25 -0
- cutienator/trial/__main__.py +59 -0
- cutienator/trial/_judge.py +589 -0
- cutienator/trial/_q_object_trials.py +38 -0
- cutienator/trial/_trial.py +495 -0
- cutienator/trial/_verdict.py +332 -0
- cutienator-0.0.1.dev0.dist-info/METADATA +33 -0
- cutienator-0.0.1.dev0.dist-info/RECORD +46 -0
- cutienator-0.0.1.dev0.dist-info/WHEEL +5 -0
- cutienator-0.0.1.dev0.dist-info/licenses/LICENSE +201 -0
- cutienator-0.0.1.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CuteSpace is the namespace the body of a cute class runs in.
|
|
3
|
+
"""
|
|
4
|
+
# Apache-2.0 license
|
|
5
|
+
# Copyright (c) 2026 Asger Jon Vistisen
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from worktoy.dispatch import overload, TypeSig
|
|
11
|
+
from worktoy.mcls import BaseSpace
|
|
12
|
+
from worktoy.mcls.space_hooks import LoadSpaceHook
|
|
13
|
+
from worktoy.waitaminute import TypeException
|
|
14
|
+
from worktoy.waitaminute.dispatch import DuplicateSignature
|
|
15
|
+
from worktoy.waitaminute.meta import OverloadConflict, ReboundOverload
|
|
16
|
+
|
|
17
|
+
from . import WAIT, WaitingOverload, CuteOverload, CuteLoadHook
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING: # pragma: no cover, no mutate
|
|
20
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
21
|
+
|
|
22
|
+
WaitingItem = Tuple[str, WaitingOverload]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CuteSpace(BaseSpace):
|
|
26
|
+
"""
|
|
27
|
+
The namespace 'MetaCute' prepares for the body of every cute class.
|
|
28
|
+
It is worktoy's 'BaseSpace' with one thing added: it keeps the
|
|
29
|
+
signatures of the body that name a late class until that class is
|
|
30
|
+
made. See 'WAIT' for the whole story; this is step 2, 4 and the
|
|
31
|
+
middle of step 6.
|
|
32
|
+
|
|
33
|
+
You never make one and seldom meet one. 'MetaCute.__prepare__' makes
|
|
34
|
+
it, the class body runs in it, and it stays with the class:
|
|
35
|
+
|
|
36
|
+
space = QObject.getNamespace() # the 'CuteSpace' of 'QObject'
|
|
37
|
+
space.getWaitingOverloads() # what of its body still waits
|
|
38
|
+
|
|
39
|
+
Terms
|
|
40
|
+
-----
|
|
41
|
+
|
|
42
|
+
- The body is the indented code under a class statement. Python runs
|
|
43
|
+
it with a namespace taking every name it binds and answering every
|
|
44
|
+
name it reads.
|
|
45
|
+
- A late class, a waiting class and a waiting signature are as
|
|
46
|
+
'WAIT' explains them.
|
|
47
|
+
- A dispatcher is the one object worktoy puts at an overloaded name,
|
|
48
|
+
which picks the function for each call.
|
|
49
|
+
|
|
50
|
+
What it adds to 'BaseSpace'
|
|
51
|
+
---------------------------
|
|
52
|
+
|
|
53
|
+
1. The body reads the name 'overload'. '__getitem__' answers with
|
|
54
|
+
'CuteOverload', unless the body bound that name itself. Every
|
|
55
|
+
read goes to 'BaseSpace' first, this one too, so the hooks of the
|
|
56
|
+
namespace see each read as worktoy shows it to them.
|
|
57
|
+
|
|
58
|
+
This is the one name the namespace answers for without the body
|
|
59
|
+
having bound it. For every other name it raises 'KeyError', as
|
|
60
|
+
'BaseSpace' does, and Python then looks in the file. A namespace
|
|
61
|
+
that answers for names it does not hold hides what the file
|
|
62
|
+
imported, so this stays the only one.
|
|
63
|
+
|
|
64
|
+
2. The body binds a name to a 'WaitingOverload', which is what
|
|
65
|
+
'CuteOverload' gives for a waiting signature. '__setitem__' takes
|
|
66
|
+
it where worktoy takes an overload of its own. The hooks ahead of
|
|
67
|
+
the one that gathers overloads are asked first, and they refuse
|
|
68
|
+
what they refuse of any binding, as '__del__' or a misspelled
|
|
69
|
+
dunder. Then it is kept in 'getWaitingOverloads' and is not
|
|
70
|
+
stored in the class. Every other binding goes to 'BaseSpace' as
|
|
71
|
+
it is.
|
|
72
|
+
|
|
73
|
+
It cannot be left to the hook that gathers overloads. That hook
|
|
74
|
+
would note a 'WaitingOverload' down as a plain definition of the
|
|
75
|
+
name, and then refuse the next real '@overload' at that name.
|
|
76
|
+
|
|
77
|
+
3. The place of every signature of a name is noted as it is written,
|
|
78
|
+
waiting or not. When a late class is made, 'nameLateClass' puts
|
|
79
|
+
each signature that waited for it back at its own place.
|
|
80
|
+
|
|
81
|
+
What to expect
|
|
82
|
+
--------------
|
|
83
|
+
|
|
84
|
+
- A body with no 'WAIT' in it behaves exactly as in a 'BaseSpace'.
|
|
85
|
+
- A waiting signature counts as an overload of its name from the
|
|
86
|
+
line it is written on: a plain definition at that name is refused
|
|
87
|
+
with 'OverloadConflict', and another kind of method at it with
|
|
88
|
+
'MixedMethodKind', both on their own line.
|
|
89
|
+
- A 'WAIT' written right into a signature, as
|
|
90
|
+
'@overload(WAIT['QThread'])', is bound in the body for you, at the
|
|
91
|
+
name of its late class, as the line 'QThread = WAIT['QThread']'
|
|
92
|
+
would. Written twice, or beside that line, it is one and the same
|
|
93
|
+
'WAIT'.
|
|
94
|
+
- A signature naming the 'WAIT' of another class, as
|
|
95
|
+
'QObject.QThread' in the body of a class built on 'QObject', is
|
|
96
|
+
refused with 'TypeError' on that line: no class would settle it,
|
|
97
|
+
and its method would be missing for ever. So is a body that deletes
|
|
98
|
+
the name of a 'WAIT' it has named, as the class is made.
|
|
99
|
+
- A waiting signature is refused wherever worktoy refuses an
|
|
100
|
+
overload: at '__del__', at a misspelled dunder as '__setname__',
|
|
101
|
+
and bound to a second name, as in '__radd__ = __add__'.
|
|
102
|
+
- Two functions at one waiting signature are refused with
|
|
103
|
+
'DuplicateSignature' on the line of the second, as worktoy refuses
|
|
104
|
+
two functions at one signature.
|
|
105
|
+
- At one of worktoy's class hooks, as '__class_call__', a waiting
|
|
106
|
+
signature is written with '@classmethod' above '@overload'.
|
|
107
|
+
- Until its late class is made, a waiting signature is in no
|
|
108
|
+
dispatcher. A name whose every signature waits is not on the class
|
|
109
|
+
at all until then.
|
|
110
|
+
- worktoy matches the signatures of one class in the order they were
|
|
111
|
+
written, so the more special one is written first. That order is
|
|
112
|
+
kept across the wait: a signature put back lands where it was
|
|
113
|
+
written, not at the end.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
117
|
+
# STATIC METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
118
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def _isOneSignature(
|
|
122
|
+
first: WaitingOverload,
|
|
123
|
+
other: WaitingOverload,
|
|
124
|
+
) -> bool:
|
|
125
|
+
"""
|
|
126
|
+
Says whether two waiting signatures will be one and the same
|
|
127
|
+
signature once their late classes are made: the same entries in the
|
|
128
|
+
same places, a 'WAIT' counting as the late class it stands for.
|
|
129
|
+
|
|
130
|
+
Parameters
|
|
131
|
+
----------
|
|
132
|
+
|
|
133
|
+
first : WaitingOverload
|
|
134
|
+
One waiting signature.
|
|
135
|
+
|
|
136
|
+
other : WaitingOverload
|
|
137
|
+
Another, written at the same name.
|
|
138
|
+
"""
|
|
139
|
+
firstEntries = first.getSignatureEntries()
|
|
140
|
+
otherEntries = other.getSignatureEntries()
|
|
141
|
+
if len(firstEntries) != len(otherEntries):
|
|
142
|
+
return False
|
|
143
|
+
for one, another in zip(firstEntries, otherEntries):
|
|
144
|
+
if one is another:
|
|
145
|
+
continue
|
|
146
|
+
if isinstance(one, WAIT) and isinstance(another, WAIT):
|
|
147
|
+
if one.getWaitingName() == another.getWaitingName():
|
|
148
|
+
continue
|
|
149
|
+
return False
|
|
150
|
+
return True
|
|
151
|
+
|
|
152
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
153
|
+
# NAMESPACE # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
154
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
155
|
+
|
|
156
|
+
# Class Variables
|
|
157
|
+
# Builds a dispatcher again after the class is made. It takes no part
|
|
158
|
+
# while the body runs; see 'CuteLoadHook'.
|
|
159
|
+
cuteLoadHook = CuteLoadHook()
|
|
160
|
+
|
|
161
|
+
# Fallback Variables
|
|
162
|
+
|
|
163
|
+
# Private Variables
|
|
164
|
+
# The waiting signatures of this body that still wait, each with the
|
|
165
|
+
# name it was written at, in the order they were written.
|
|
166
|
+
__waiting_overloads__: Optional[List[WaitingItem]] = None
|
|
167
|
+
# For each overloaded name of this body, everything written at it in
|
|
168
|
+
# order: a worktoy signature for one that is on record, the
|
|
169
|
+
# 'WaitingOverload' itself for one that still waits.
|
|
170
|
+
__declared_signatures__: Optional[Dict[str, List[Any]]] = None
|
|
171
|
+
|
|
172
|
+
# Public Variables
|
|
173
|
+
|
|
174
|
+
# Virtual Variables
|
|
175
|
+
|
|
176
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
177
|
+
# GETTERS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
178
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
179
|
+
|
|
180
|
+
def _getWaitingList(self) -> List[WaitingItem]:
|
|
181
|
+
"""Gives the list behind 'getWaitingOverloads', making it if need be."""
|
|
182
|
+
if self.__waiting_overloads__ is None:
|
|
183
|
+
self.__waiting_overloads__ = []
|
|
184
|
+
return self.__waiting_overloads__
|
|
185
|
+
|
|
186
|
+
def getWaitingOverloads(self) -> Tuple[WaitingItem, ...]:
|
|
187
|
+
"""
|
|
188
|
+
Gives the waiting signatures of this body that still wait, in the
|
|
189
|
+
order they were written.
|
|
190
|
+
|
|
191
|
+
Kept for you: '__setitem__' adds each one as the body binds it, and
|
|
192
|
+
'nameLateClass' removes each one whose last late class is made.
|
|
193
|
+
|
|
194
|
+
Returns
|
|
195
|
+
-------
|
|
196
|
+
|
|
197
|
+
Tuple[WaitingItem, ...]
|
|
198
|
+
A 'Tuple[Tuple[str, WaitingOverload], ...]': the name the
|
|
199
|
+
signature was written at, as 'moveToThread', and the
|
|
200
|
+
'WaitingOverload' holding its entries and its function. It is
|
|
201
|
+
empty for a body that waits for nothing, and again once every
|
|
202
|
+
late class of the body is made.
|
|
203
|
+
"""
|
|
204
|
+
return (*self._getWaitingList(),)
|
|
205
|
+
|
|
206
|
+
def _getDeclaredSignatures(self, methodName: str) -> List[Any]:
|
|
207
|
+
"""
|
|
208
|
+
Gives everything this body wrote at one overloaded name, in the
|
|
209
|
+
order it was written: a worktoy signature for each one that is on
|
|
210
|
+
record, and the 'WaitingOverload' itself for each one that still
|
|
211
|
+
waits. The list is the one kept, so changing it changes the note.
|
|
212
|
+
"""
|
|
213
|
+
if self.__declared_signatures__ is None:
|
|
214
|
+
self.__declared_signatures__ = dict()
|
|
215
|
+
return self.__declared_signatures__.setdefault(methodName, [])
|
|
216
|
+
|
|
217
|
+
def keepRecords(self) -> Dict[str, Any]:
|
|
218
|
+
"""
|
|
219
|
+
Gives a copy of everything 'nameLateClass' changes, for
|
|
220
|
+
'restoreRecords' to put back.
|
|
221
|
+
|
|
222
|
+
'MetaCute' calls this before it has a late class named here. When
|
|
223
|
+
the late class cannot be named in every class that waits for it,
|
|
224
|
+
each namespace that was changed is put back as it was.
|
|
225
|
+
|
|
226
|
+
Returns
|
|
227
|
+
-------
|
|
228
|
+
|
|
229
|
+
Dict[str, Any]
|
|
230
|
+
The signatures on record for each name, the waiting signatures
|
|
231
|
+
with the entries of each, and the place of everything written.
|
|
232
|
+
It is for 'restoreRecords' alone.
|
|
233
|
+
"""
|
|
234
|
+
waitingList = self._getWaitingList()
|
|
235
|
+
declared = self.__declared_signatures__ or dict()
|
|
236
|
+
overloads = self.getOverloads()
|
|
237
|
+
return dict(
|
|
238
|
+
onRecord={name: [*pairs] for name, pairs in overloads.items()},
|
|
239
|
+
waitingList=[*waitingList],
|
|
240
|
+
entries=[(w, w.getSignatureEntries()) for _, w in waitingList],
|
|
241
|
+
declared={name: [*written] for name, written in declared.items()},
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
def _findOwnWait(self, wait: WAIT) -> Optional[WAIT]:
|
|
245
|
+
"""
|
|
246
|
+
Gives the 'WAIT' this body binds for the late class that 'wait'
|
|
247
|
+
stands for: 'wait' itself when the body binds it, else another
|
|
248
|
+
'WAIT' the body binds for the same late class, else None.
|
|
249
|
+
"""
|
|
250
|
+
lateName = wait.getWaitingName()
|
|
251
|
+
found = None
|
|
252
|
+
for value in dict.values(self):
|
|
253
|
+
if value is wait:
|
|
254
|
+
return wait
|
|
255
|
+
if found is None and isinstance(value, WAIT):
|
|
256
|
+
if value.getWaitingName() == lateName:
|
|
257
|
+
found = value
|
|
258
|
+
return found
|
|
259
|
+
|
|
260
|
+
def _createOwnWait(self, methodName: str, wait: WAIT) -> None:
|
|
261
|
+
"""
|
|
262
|
+
Binds a 'WAIT' that a signature names and no line of the body binds,
|
|
263
|
+
at the name of its late class, as the line
|
|
264
|
+
'QThread = WAIT['QThread']' would.
|
|
265
|
+
|
|
266
|
+
The name is bound through '__setitem__', as any line of the body
|
|
267
|
+
binds one, so the hooks of worktoy see it as well.
|
|
268
|
+
|
|
269
|
+
Parameters
|
|
270
|
+
----------
|
|
271
|
+
|
|
272
|
+
methodName : str
|
|
273
|
+
The name the signature is written at, for the messages.
|
|
274
|
+
|
|
275
|
+
wait : WAIT
|
|
276
|
+
The 'WAIT' the signature names.
|
|
277
|
+
|
|
278
|
+
Raises
|
|
279
|
+
------
|
|
280
|
+
|
|
281
|
+
TypeError
|
|
282
|
+
'wait' is bound in the body of another class, which alone it is
|
|
283
|
+
settled for, or the name of its late class is taken in this body
|
|
284
|
+
already.
|
|
285
|
+
"""
|
|
286
|
+
className = self.getClassName()
|
|
287
|
+
lateName = wait.getWaitingName()
|
|
288
|
+
owner = wait.getFieldOwner()
|
|
289
|
+
if owner is not None:
|
|
290
|
+
infoSpec = """'%s.%s' names a 'WAIT' bound in the body of '%s'. No
|
|
291
|
+
class settles it for '%s', so the method would be missing for
|
|
292
|
+
ever. Give the body of '%s' a line of its own, above the method:
|
|
293
|
+
%s = %s"""
|
|
294
|
+
info = infoSpec % (
|
|
295
|
+
className, methodName, owner.__name__, className, className,
|
|
296
|
+
lateName, wait,
|
|
297
|
+
)
|
|
298
|
+
raise TypeError(' '.join(info.split()))
|
|
299
|
+
taken = dict.__contains__(self, lateName)
|
|
300
|
+
if taken or lateName in self.getShadowSpace():
|
|
301
|
+
infoSpec = """'%s.%s' names %s, which no line of the body of '%s'
|
|
302
|
+
binds, and the name '%s' is taken there already, so it cannot be
|
|
303
|
+
bound at that name for you. Bind it yourself at a name that is
|
|
304
|
+
free, on a line above the method, and name that in the
|
|
305
|
+
signature."""
|
|
306
|
+
info = infoSpec % (className, methodName, wait, className, lateName)
|
|
307
|
+
raise TypeError(' '.join(info.split()))
|
|
308
|
+
self[lateName] = wait
|
|
309
|
+
|
|
310
|
+
def _getOwnWait(self, methodName: str, wait: WAIT, **kwargs) -> WAIT:
|
|
311
|
+
"""
|
|
312
|
+
Gives the 'WAIT' of this body that stands for the late class a
|
|
313
|
+
signature names, binding one first when the body has none.
|
|
314
|
+
|
|
315
|
+
A signature may name a 'WAIT' the body bound on a line of its own,
|
|
316
|
+
or one written right into it, as '@overload(WAIT['QThread'])'.
|
|
317
|
+
Either way it comes out as one 'WAIT' per late class, bound at a
|
|
318
|
+
name of the body, which is what 'MetaCute' settles.
|
|
319
|
+
|
|
320
|
+
Parameters
|
|
321
|
+
----------
|
|
322
|
+
|
|
323
|
+
methodName : str
|
|
324
|
+
The name the signature is written at, for the messages.
|
|
325
|
+
|
|
326
|
+
wait : WAIT
|
|
327
|
+
The 'WAIT' the signature names. The keyword is for the method's
|
|
328
|
+
own use.
|
|
329
|
+
|
|
330
|
+
Returns
|
|
331
|
+
-------
|
|
332
|
+
|
|
333
|
+
WAIT
|
|
334
|
+
'wait' itself when the body binds it, or was just made to; else
|
|
335
|
+
the 'WAIT' the body binds for the same late class.
|
|
336
|
+
|
|
337
|
+
Raises
|
|
338
|
+
------
|
|
339
|
+
|
|
340
|
+
TypeError
|
|
341
|
+
As '_createOwnWait' raises it.
|
|
342
|
+
"""
|
|
343
|
+
ownWait = self._findOwnWait(wait)
|
|
344
|
+
if ownWait is None:
|
|
345
|
+
if kwargs.get('_recursion', False):
|
|
346
|
+
raise RecursionError
|
|
347
|
+
self._createOwnWait(methodName, wait)
|
|
348
|
+
return self._getOwnWait(methodName, wait, _recursion=True)
|
|
349
|
+
return ownWait
|
|
350
|
+
|
|
351
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
352
|
+
# SETTERS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
353
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
354
|
+
|
|
355
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
356
|
+
# NOTIFIERS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
357
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
358
|
+
|
|
359
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
360
|
+
# Python API # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
361
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
362
|
+
|
|
363
|
+
def __getitem__(self, key: str, **kwargs) -> Any:
|
|
364
|
+
"""
|
|
365
|
+
Answers a name the class body reads. Python asks here first, and
|
|
366
|
+
looks in the file only when this raises 'KeyError'.
|
|
367
|
+
|
|
368
|
+
Every read goes to 'BaseSpace' first, which shows it to the hooks
|
|
369
|
+
of the namespace. The name 'overload' is then answered with
|
|
370
|
+
'CuteOverload' when the body did not bind that name itself. So
|
|
371
|
+
'@overload(...)' in a cute body is always 'CuteOverload', whatever
|
|
372
|
+
the file imported under the name, and that is what lets a
|
|
373
|
+
signature name a 'WAIT'.
|
|
374
|
+
|
|
375
|
+
Parameters
|
|
376
|
+
----------
|
|
377
|
+
|
|
378
|
+
key : str
|
|
379
|
+
The name read.
|
|
380
|
+
|
|
381
|
+
Returns
|
|
382
|
+
-------
|
|
383
|
+
|
|
384
|
+
Any
|
|
385
|
+
'CuteOverload' for 'overload', else what the body bound at the
|
|
386
|
+
name.
|
|
387
|
+
|
|
388
|
+
Raises
|
|
389
|
+
------
|
|
390
|
+
|
|
391
|
+
KeyError
|
|
392
|
+
The body never bound the name, and it is not 'overload'. Python
|
|
393
|
+
then looks among the names of the file.
|
|
394
|
+
|
|
395
|
+
HookException
|
|
396
|
+
A hook of the namespace refused the read.
|
|
397
|
+
"""
|
|
398
|
+
try:
|
|
399
|
+
return BaseSpace.__getitem__(self, key, **kwargs)
|
|
400
|
+
except KeyError:
|
|
401
|
+
if key == 'overload':
|
|
402
|
+
return CuteOverload
|
|
403
|
+
raise
|
|
404
|
+
|
|
405
|
+
def __setitem__(self, key: str, val: Any, **kwargs) -> None:
|
|
406
|
+
"""
|
|
407
|
+
Takes a name the class body binds. Python calls this for every
|
|
408
|
+
assignment, function and class statement of the body.
|
|
409
|
+
|
|
410
|
+
A 'WaitingOverload', with or without a 'classmethod' or
|
|
411
|
+
'staticmethod' around it, is taken where worktoy takes an overload
|
|
412
|
+
of its own. The hooks ahead of the one that gathers overloads are
|
|
413
|
+
asked first, in their order, and refuse what they refuse of any
|
|
414
|
+
binding. A 'WAIT' the signature names that no line of the body
|
|
415
|
+
binds is bound first, at the name of its late class. Then the
|
|
416
|
+
'WaitingOverload' is kept in 'getWaitingOverloads' and goes no
|
|
417
|
+
further: it is not stored in the class. Everything else goes to
|
|
418
|
+
'BaseSpace' as it is, and the signatures worktoy puts on record
|
|
419
|
+
for it are noted in the order of the body.
|
|
420
|
+
|
|
421
|
+
Parameters
|
|
422
|
+
----------
|
|
423
|
+
|
|
424
|
+
key : str
|
|
425
|
+
The name bound.
|
|
426
|
+
|
|
427
|
+
val : Any
|
|
428
|
+
The value bound.
|
|
429
|
+
|
|
430
|
+
Raises
|
|
431
|
+
------
|
|
432
|
+
|
|
433
|
+
OverloadConflict
|
|
434
|
+
A waiting signature is written at a name the body defined plainly
|
|
435
|
+
before.
|
|
436
|
+
|
|
437
|
+
ReboundOverload
|
|
438
|
+
A waiting signature is bound a second time in the body, as in
|
|
439
|
+
'__radd__ = __add__'.
|
|
440
|
+
|
|
441
|
+
MixedMethodKind
|
|
442
|
+
A waiting signature is written as another kind of method than the
|
|
443
|
+
name has in this body already, or as both a classmethod and a
|
|
444
|
+
staticmethod.
|
|
445
|
+
|
|
446
|
+
DelException, QuestionableSyntax, UnboundClassHook, ReservedName
|
|
447
|
+
A waiting signature is written at a name worktoy refuses, or
|
|
448
|
+
refuses for what is bound there. They come from the hooks of
|
|
449
|
+
worktoy, as for any binding.
|
|
450
|
+
|
|
451
|
+
TypeError
|
|
452
|
+
A waiting signature names a 'WAIT' bound in the body of another
|
|
453
|
+
class, or one no line binds whose name is taken in this body; see
|
|
454
|
+
'_createOwnWait'.
|
|
455
|
+
|
|
456
|
+
DuplicateSignature
|
|
457
|
+
A waiting signature is written at a name that already has the
|
|
458
|
+
same waiting signature for another function. Once the late class
|
|
459
|
+
is made the two would be one signature.
|
|
460
|
+
"""
|
|
461
|
+
methodKinds, bound = overload.peelMethodKinds(val)
|
|
462
|
+
if not isinstance(bound, WaitingOverload):
|
|
463
|
+
before = len(self.getOverloads().get(key, []))
|
|
464
|
+
BaseSpace.__setitem__(self, key, val, **kwargs)
|
|
465
|
+
for signature, _ in self.getOverloads().get(key, [])[before:]:
|
|
466
|
+
self._getDeclaredSignatures(key).append(signature)
|
|
467
|
+
return
|
|
468
|
+
className = self.getClassName()
|
|
469
|
+
# The body may read the name again further down, and deleting it is
|
|
470
|
+
# refused as for any overload: both go by this note of 'BaseSpace',
|
|
471
|
+
# which takes every binding before a hook is asked.
|
|
472
|
+
shadowSpace = self.getShadowSpace()
|
|
473
|
+
shadowSpace[key] = val
|
|
474
|
+
self.__shadow_space__ = shadowSpace
|
|
475
|
+
try:
|
|
476
|
+
oldVal = dict.__getitem__(self, key)
|
|
477
|
+
except KeyError:
|
|
478
|
+
oldVal = None
|
|
479
|
+
# The hooks ahead of the one that gathers overloads screen the
|
|
480
|
+
# binding. One of them taking it for itself ends it here, as it
|
|
481
|
+
# ends an overload of worktoy's own.
|
|
482
|
+
for hook in self.getHooks():
|
|
483
|
+
if isinstance(hook, LoadSpaceHook):
|
|
484
|
+
break
|
|
485
|
+
if hook.setItemPhase(key, val, oldVal):
|
|
486
|
+
return
|
|
487
|
+
if key in self.getPlainNames():
|
|
488
|
+
raise OverloadConflict(className, key, False)
|
|
489
|
+
claimedName = self.getClaimedName(bound)
|
|
490
|
+
if claimedName is not None:
|
|
491
|
+
raise ReboundOverload(className, claimedName, key)
|
|
492
|
+
methodKinds = (*methodKinds, *bound.getMethodKinds())
|
|
493
|
+
methodKind = overload.agreeMethodKind(methodKinds, key, className)
|
|
494
|
+
self.addMethodKind(key, methodKind)
|
|
495
|
+
# Every 'WAIT' the signature names becomes the one this body binds
|
|
496
|
+
# for that late class. One written right into the signature is bound
|
|
497
|
+
# here, by this very method.
|
|
498
|
+
entries = []
|
|
499
|
+
for entry in bound.getSignatureEntries():
|
|
500
|
+
if isinstance(entry, WAIT):
|
|
501
|
+
entry = self._getOwnWait(key, entry)
|
|
502
|
+
entries.append(entry)
|
|
503
|
+
bound.setSignatureEntries(*entries)
|
|
504
|
+
# Two functions at what will be one signature are refused here, on
|
|
505
|
+
# the line of the second, as worktoy refuses them for an overload
|
|
506
|
+
# of its own. One function written there twice is taken once.
|
|
507
|
+
for heldName, held in self._getWaitingList():
|
|
508
|
+
if heldName != key or not self._isOneSignature(held, bound):
|
|
509
|
+
continue
|
|
510
|
+
heldFunction, function = held.getFunction(), bound.getFunction()
|
|
511
|
+
if heldFunction is function:
|
|
512
|
+
return
|
|
513
|
+
raise DuplicateSignature(held, heldFunction, function)
|
|
514
|
+
self.addClaimedName(bound, key)
|
|
515
|
+
self._getWaitingList().append((key, bound))
|
|
516
|
+
self._getDeclaredSignatures(key).append(bound)
|
|
517
|
+
|
|
518
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
519
|
+
# CONSTRUCTORS # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
520
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
521
|
+
|
|
522
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
523
|
+
# DOMAIN SPECIFIC # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
524
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
525
|
+
|
|
526
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
527
|
+
# OPTIONAL METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
528
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
529
|
+
|
|
530
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
531
|
+
# REQUIRED METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
532
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
533
|
+
|
|
534
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
535
|
+
# PARENT METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
536
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
537
|
+
|
|
538
|
+
def hasOverloads(self, name: str) -> bool:
|
|
539
|
+
"""
|
|
540
|
+
Says whether the body declared an overload at a name, a waiting
|
|
541
|
+
signature counting as one.
|
|
542
|
+
|
|
543
|
+
worktoy asks this when the body binds a plain value, and refuses
|
|
544
|
+
the binding with 'OverloadConflict' when the answer is True. With
|
|
545
|
+
the waiting signatures counted, a plain definition written after a
|
|
546
|
+
waiting signature of the same name is refused as well, where it
|
|
547
|
+
would otherwise take the name and leave the signature with nothing
|
|
548
|
+
to come back to.
|
|
549
|
+
|
|
550
|
+
Parameters
|
|
551
|
+
----------
|
|
552
|
+
|
|
553
|
+
name : str
|
|
554
|
+
The name asked about.
|
|
555
|
+
"""
|
|
556
|
+
for methodName, _ in self._getWaitingList():
|
|
557
|
+
if methodName == name:
|
|
558
|
+
return True
|
|
559
|
+
return BaseSpace.hasOverloads(self, name)
|
|
560
|
+
|
|
561
|
+
def postCompile(self, namespace: dict) -> dict:
|
|
562
|
+
"""
|
|
563
|
+
Checks, as the body ends, that every 'WAIT' a waiting signature of
|
|
564
|
+
the body names is still bound in it.
|
|
565
|
+
|
|
566
|
+
worktoy calls this once, when the class is about to be made, after
|
|
567
|
+
its hooks have built the dispatchers. A line binding a 'WAIT' for
|
|
568
|
+
the same late class further down the body takes the place of the
|
|
569
|
+
one a signature named. A body that deletes the name of a 'WAIT' it
|
|
570
|
+
has named, or binds that name to something else, is refused: the
|
|
571
|
+
class would hold no 'WAIT' to be settled, and the signature would
|
|
572
|
+
wait for ever.
|
|
573
|
+
|
|
574
|
+
Parameters
|
|
575
|
+
----------
|
|
576
|
+
|
|
577
|
+
namespace : dict
|
|
578
|
+
The dictionary the class is made from, as worktoy assembled it.
|
|
579
|
+
|
|
580
|
+
Returns
|
|
581
|
+
-------
|
|
582
|
+
|
|
583
|
+
dict
|
|
584
|
+
The same dictionary, unchanged.
|
|
585
|
+
|
|
586
|
+
Raises
|
|
587
|
+
------
|
|
588
|
+
|
|
589
|
+
TypeError
|
|
590
|
+
A waiting signature names a 'WAIT' for a late class that the body
|
|
591
|
+
binds no 'WAIT' for any more.
|
|
592
|
+
"""
|
|
593
|
+
namespace = BaseSpace.postCompile(self, namespace)
|
|
594
|
+
className = self.getClassName()
|
|
595
|
+
for methodName, waitingOverload in self.getWaitingOverloads():
|
|
596
|
+
entries = []
|
|
597
|
+
for entry in waitingOverload.getSignatureEntries():
|
|
598
|
+
if isinstance(entry, WAIT):
|
|
599
|
+
ownWait = self._findOwnWait(entry)
|
|
600
|
+
if ownWait is None:
|
|
601
|
+
infoSpec = """'%s.%s' names %s, and the body of '%s' no
|
|
602
|
+
longer binds it as it ends: its name was deleted or bound
|
|
603
|
+
to something else. Nothing settles it, so the method would
|
|
604
|
+
be missing for ever."""
|
|
605
|
+
info = infoSpec % (className, methodName, entry, className)
|
|
606
|
+
raise TypeError(' '.join(info.split()))
|
|
607
|
+
entry = ownWait
|
|
608
|
+
entries.append(entry)
|
|
609
|
+
waitingOverload.setSignatureEntries(*entries)
|
|
610
|
+
return namespace
|
|
611
|
+
|
|
612
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
613
|
+
# PUBLIC METHODS # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
614
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
615
|
+
|
|
616
|
+
def restoreRecords(self, records: Dict[str, Any]) -> None:
|
|
617
|
+
"""
|
|
618
|
+
Puts back what 'keepRecords' copied: the namespace has on record,
|
|
619
|
+
and keeps waiting, exactly what it did when the copy was taken.
|
|
620
|
+
|
|
621
|
+
Parameters
|
|
622
|
+
----------
|
|
623
|
+
|
|
624
|
+
records : Dict[str, Any]
|
|
625
|
+
What 'keepRecords' gave.
|
|
626
|
+
"""
|
|
627
|
+
onRecord, declared = records['onRecord'], records['declared']
|
|
628
|
+
self.__overload_map__ = {n: [*pairs] for n, pairs in onRecord.items()}
|
|
629
|
+
self.__waiting_overloads__ = [*records['waitingList']]
|
|
630
|
+
self.__declared_signatures__ = {n: [*w] for n, w in declared.items()}
|
|
631
|
+
for waitingOverload, entries in records['entries']:
|
|
632
|
+
waitingOverload.setSignatureEntries(*entries)
|
|
633
|
+
|
|
634
|
+
def nameLateClass(self, wait: WAIT, lateClass: type) -> Tuple[str, ...]:
|
|
635
|
+
"""
|
|
636
|
+
Tells the namespace that a late class its body waited for is made,
|
|
637
|
+
and has it put the signatures that waited for it back on record.
|
|
638
|
+
|
|
639
|
+
'MetaCute' calls this, once for each 'WAIT' of the waiting class
|
|
640
|
+
that the new class settles. You never call it. In every waiting
|
|
641
|
+
signature the 'WAIT' is replaced by the class. A signature with no
|
|
642
|
+
'WAIT' left is put on record through 'BaseSpace.addOverload', at
|
|
643
|
+
the place it was written in, and waits no more. One still naming
|
|
644
|
+
another late class stays among 'getWaitingOverloads'.
|
|
645
|
+
|
|
646
|
+
Nothing is built here. The dispatchers of the names given back are
|
|
647
|
+
out of date from this moment on, and 'MetaCute' builds them again.
|
|
648
|
+
|
|
649
|
+
It is all or nothing. When worktoy refuses one of the signatures,
|
|
650
|
+
the namespace is put back as it was before the call.
|
|
651
|
+
|
|
652
|
+
Parameters
|
|
653
|
+
----------
|
|
654
|
+
|
|
655
|
+
wait : WAIT
|
|
656
|
+
The 'WAIT' of this body that stood for the class.
|
|
657
|
+
|
|
658
|
+
lateClass : type
|
|
659
|
+
The class, now made.
|
|
660
|
+
|
|
661
|
+
Returns
|
|
662
|
+
-------
|
|
663
|
+
|
|
664
|
+
Tuple[str, ...]
|
|
665
|
+
The names that got a signature back, as 'moveToThread', each
|
|
666
|
+
once, in the order their signatures were written. It is empty
|
|
667
|
+
when no signature became complete.
|
|
668
|
+
|
|
669
|
+
Raises
|
|
670
|
+
------
|
|
671
|
+
|
|
672
|
+
TypeException
|
|
673
|
+
'wait' is not a 'WAIT', or 'lateClass' is not a class.
|
|
674
|
+
|
|
675
|
+
DuplicateSignature
|
|
676
|
+
The signature put back equals one the body already declared at
|
|
677
|
+
that name for another function. Nothing is changed then.
|
|
678
|
+
"""
|
|
679
|
+
if not isinstance(wait, WAIT):
|
|
680
|
+
raise TypeException('wait', wait, WAIT)
|
|
681
|
+
if not isinstance(lateClass, type):
|
|
682
|
+
raise TypeException('lateClass', lateClass, type)
|
|
683
|
+
records = self.keepRecords()
|
|
684
|
+
try:
|
|
685
|
+
return self._nameLateClass(wait, lateClass)
|
|
686
|
+
except BaseException:
|
|
687
|
+
self.restoreRecords(records)
|
|
688
|
+
raise
|
|
689
|
+
|
|
690
|
+
def _nameLateClass(self, wait: WAIT, lateClass: type) -> Tuple[str, ...]:
|
|
691
|
+
"""
|
|
692
|
+
Does the work of 'nameLateClass', which puts the namespace back as
|
|
693
|
+
it was when this raises half way.
|
|
694
|
+
"""
|
|
695
|
+
methodNames = [] # type: List[str]
|
|
696
|
+
for waitingItem in self.getWaitingOverloads():
|
|
697
|
+
methodName, waitingOverload = waitingItem
|
|
698
|
+
entries = waitingOverload.getSignatureEntries()
|
|
699
|
+
if not any(entry is wait for entry in entries):
|
|
700
|
+
continue
|
|
701
|
+
entries = (*(lateClass if e is wait else e for e in entries),)
|
|
702
|
+
waitingOverload.setSignatureEntries(*entries)
|
|
703
|
+
if any(isinstance(entry, WAIT) for entry in entries):
|
|
704
|
+
continue
|
|
705
|
+
self._getWaitingList().remove(waitingItem)
|
|
706
|
+
signature = TypeSig(*entries)
|
|
707
|
+
before = len(self.getOverloads().get(methodName, []))
|
|
708
|
+
self.addOverload(methodName, signature, waitingOverload.getFunction())
|
|
709
|
+
declared = self._getDeclaredSignatures(methodName)
|
|
710
|
+
written = declared.index(waitingOverload)
|
|
711
|
+
onRecord = self.getOverloads()[methodName]
|
|
712
|
+
if len(onRecord) == before:
|
|
713
|
+
# worktoy had the same signature for the same function already,
|
|
714
|
+
# and took nothing new.
|
|
715
|
+
del declared[written]
|
|
716
|
+
else:
|
|
717
|
+
# 'addOverload' put it last. It belongs before every signature
|
|
718
|
+
# that was written after it and is on record.
|
|
719
|
+
place = sum(
|
|
720
|
+
1 for earlier in declared[:written]
|
|
721
|
+
if isinstance(earlier, TypeSig)
|
|
722
|
+
)
|
|
723
|
+
onRecord.insert(place, onRecord.pop())
|
|
724
|
+
declared[written] = signature
|
|
725
|
+
if methodName not in methodNames:
|
|
726
|
+
methodNames.append(methodName)
|
|
727
|
+
return (*methodNames,)
|