worktoy 1.2.3.dev0__py3-none-any.whl → 1.2.3.dev1__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.
- worktoy/__init__.py +1 -1
- worktoy/dispatch/_dispatcher.py +16 -1
- worktoy/dispatch/_overload.py +35 -6
- worktoy/mcls/_base_space.py +142 -23
- worktoy/mcls/space_hooks/_load_space_hook.py +59 -21
- {worktoy-1.2.3.dev0.dist-info → worktoy-1.2.3.dev1.dist-info}/METADATA +2 -2
- {worktoy-1.2.3.dev0.dist-info → worktoy-1.2.3.dev1.dist-info}/RECORD +10 -10
- {worktoy-1.2.3.dev0.dist-info → worktoy-1.2.3.dev1.dist-info}/WHEEL +0 -0
- {worktoy-1.2.3.dev0.dist-info → worktoy-1.2.3.dev1.dist-info}/licenses/LICENSE +0 -0
- {worktoy-1.2.3.dev0.dist-info → worktoy-1.2.3.dev1.dist-info}/top_level.txt +0 -0
worktoy/__init__.py
CHANGED
|
@@ -48,7 +48,7 @@ and the enclosing class is left without the decoration.
|
|
|
48
48
|
# Copyright (c) 2025-2026 Asger Jon Vistisen
|
|
49
49
|
from __future__ import annotations
|
|
50
50
|
|
|
51
|
-
__version__ = '1.2.3-
|
|
51
|
+
__version__ = '1.2.3-dev1'
|
|
52
52
|
|
|
53
53
|
from . import utilities
|
|
54
54
|
from . import waitaminute
|
worktoy/dispatch/_dispatcher.py
CHANGED
|
@@ -305,7 +305,13 @@ class Dispatcher(Object):
|
|
|
305
305
|
given by 'setClassDispatcher', which holds the classmethods and the
|
|
306
306
|
staticmethods, and hands a read through the class on to it. A bound
|
|
307
307
|
method is therefore not considered through the class, nor a
|
|
308
|
-
staticmethod through an instance.
|
|
308
|
+
staticmethod through an instance. Where no overload of the name is a
|
|
309
|
+
bound method, only its fallback or its finalizer, the first holds the
|
|
310
|
+
staticmethods as well, so a fallback takes no call away from an
|
|
311
|
+
overload. Each of the two holds a fallback of
|
|
312
|
+
its own: the one reached through an instance the instance bound
|
|
313
|
+
fallback of the name, and the one reached through the class its class
|
|
314
|
+
bound fallback.
|
|
309
315
|
|
|
310
316
|
Attributes
|
|
311
317
|
----------
|
|
@@ -1334,6 +1340,15 @@ class Dispatcher(Object):
|
|
|
1334
1340
|
A call that no signature accepts, by class, by length or by cast, may
|
|
1335
1341
|
need a function of its own instead of an error.
|
|
1336
1342
|
|
|
1343
|
+
Implementation
|
|
1344
|
+
--------------
|
|
1345
|
+
|
|
1346
|
+
A dispatcher holds one fallback. A name holding bound methods beside
|
|
1347
|
+
another kind has two dispatchers and so two fallbacks, apart: the
|
|
1348
|
+
dispatcher reached through an instance holds the instance bound
|
|
1349
|
+
fallback, and the one reached through the class the class bound
|
|
1350
|
+
fallback.
|
|
1351
|
+
|
|
1337
1352
|
Parameters
|
|
1338
1353
|
----------
|
|
1339
1354
|
|
worktoy/dispatch/_overload.py
CHANGED
|
@@ -77,11 +77,15 @@ class overload: # NOQA
|
|
|
77
77
|
classmethods and the staticmethods are reached through the class, the
|
|
78
78
|
bound methods and the classmethods through an instance, and a
|
|
79
79
|
staticmethod is not considered through an instance where the name has
|
|
80
|
-
a bound
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
a bound overload. The fallbacks of a name are two, apart: the instance
|
|
81
|
+
bound fallback, declared as a bound method, takes a call through an
|
|
82
|
+
instance that nothing accepts, and the class bound fallback, declared
|
|
83
|
+
as a staticmethod, takes such a call through the class; one declared
|
|
84
|
+
as a classmethod is both. A subclass declaring an overload at a name
|
|
85
|
+
it inherits keeps the inherited overloads and adds its own, an equal
|
|
86
|
+
signature replacing the inherited one. A subclass overloading the name
|
|
87
|
+
only as kinds of method the inherited declarations are not overrides
|
|
88
|
+
it as a plain definition does, hiding the inherited overloads.
|
|
85
89
|
"""
|
|
86
90
|
|
|
87
91
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
@@ -507,7 +511,32 @@ class overload: # NOQA
|
|
|
507
511
|
def fallback(cls, func) -> Self:
|
|
508
512
|
"""
|
|
509
513
|
A call no declaration of the name accepts may need a function of its
|
|
510
|
-
own instead of an error.
|
|
514
|
+
own instead of an error. A name holding bound methods beside
|
|
515
|
+
staticmethods is reached two ways, through an instance and through
|
|
516
|
+
the class, and may need such a function for each way.
|
|
517
|
+
|
|
518
|
+
Implementation
|
|
519
|
+
--------------
|
|
520
|
+
|
|
521
|
+
The function is recorded as a fallback of its name, as the kind of
|
|
522
|
+
method the stack declares it. The fallbacks of a name are two, apart:
|
|
523
|
+
|
|
524
|
+
- The instance bound fallback takes a call through an instance that
|
|
525
|
+
nothing accepts. A fallback declared as a bound method is instance
|
|
526
|
+
bound, and receives the instance.
|
|
527
|
+
- The class bound fallback takes such a call through the class. A
|
|
528
|
+
fallback declared as a staticmethod is class bound, and receives
|
|
529
|
+
the arguments alone.
|
|
530
|
+
|
|
531
|
+
A fallback declared as a classmethod is both at once, receiving the
|
|
532
|
+
class either way, so it stands alone at its name. A name may thus
|
|
533
|
+
hold one bound fallback and one static fallback, and any other two
|
|
534
|
+
are refused with 'DuplicateSignature' as the class body binds the
|
|
535
|
+
second. At a name holding no bound overload the staticmethods are
|
|
536
|
+
tried through an instance as well, and so is its class bound
|
|
537
|
+
fallback, unless the name has an instance bound fallback, which then
|
|
538
|
+
takes those calls. A fallback thus takes no call away from an
|
|
539
|
+
overload that accepts it.
|
|
511
540
|
|
|
512
541
|
Parameters
|
|
513
542
|
----------
|
worktoy/mcls/_base_space.py
CHANGED
|
@@ -22,6 +22,7 @@ if TYPE_CHECKING: # pragma: no cover, no mutate
|
|
|
22
22
|
SigFuncList: TypeAlias = list[SigFunc]
|
|
23
23
|
OverloadMap: TypeAlias = dict[str, SigFuncList]
|
|
24
24
|
FuncMap: TypeAlias = dict[str, Callable[..., Any]]
|
|
25
|
+
FuncListMap: TypeAlias = dict[str, list[Callable[..., Any]]]
|
|
25
26
|
Collected: TypeAlias = tuple[TypeSig, Callable[..., Any], int]
|
|
26
27
|
CollectedList: TypeAlias = list[Collected]
|
|
27
28
|
Claim: TypeAlias = tuple[overload, str]
|
|
@@ -55,19 +56,29 @@ class BaseSpace(AbstractNamespace):
|
|
|
55
56
|
kind. A bound method is reached through an instance and a staticmethod
|
|
56
57
|
through the class, so the two never answer one call and may share a
|
|
57
58
|
signature; any other two functions of one signature at a name would
|
|
58
|
-
leave dispatch undecided.
|
|
59
|
-
|
|
59
|
+
leave dispatch undecided. The fallbacks of a name are two, apart: the
|
|
60
|
+
instance bound fallback takes a call through an instance that nothing
|
|
61
|
+
accepts, and the class bound fallback takes such a call through the
|
|
62
|
+
class. A fallback declared as a bound method is instance bound, one
|
|
63
|
+
declared as a staticmethod is class bound, and one declared as a
|
|
64
|
+
classmethod is both, so a name may hold a bound fallback and a static
|
|
65
|
+
one, and any other two would leave it undecided which one takes a
|
|
66
|
+
call. A base declaring the name as kinds none of which the nearer
|
|
67
|
+
classes declare is hidden as a plain definition is.
|
|
60
68
|
|
|
61
69
|
Implementation
|
|
62
70
|
--------------
|
|
63
71
|
|
|
64
72
|
'loadSpaceHook' records the declarations of the body through
|
|
65
73
|
'addOverload', 'addVariadic', 'addFallback' and 'addFinalizer'; one body
|
|
66
|
-
may not declare one signature
|
|
67
|
-
|
|
68
|
-
'
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
may not declare one signature or finalizer twice for different
|
|
75
|
+
functions, nor two fallbacks that one call could reach.
|
|
76
|
+
'collectOverloads', 'collectVariadics', 'collectFallbacks' and
|
|
77
|
+
'collectFinalizer' gather the declarations of the body and of the
|
|
78
|
+
'BaseSpace' namespaces of the bases, with distances, 0 for the body;
|
|
79
|
+
'collectFallback' gives the nearest fallback alone, and
|
|
80
|
+
'collectFallbacks' begins with it. 'addMethodKind' records the kinds
|
|
81
|
+
each name is declared
|
|
71
82
|
as and 'addFunctionKind' the kind of each function, and
|
|
72
83
|
'_getInheritedSpaces' passes over a base sharing no kind with the
|
|
73
84
|
nearer classes as it passes over a plain definition.
|
|
@@ -89,7 +100,7 @@ class BaseSpace(AbstractNamespace):
|
|
|
89
100
|
__overload_map__: Optional[OverloadMap] = None
|
|
90
101
|
__variadic_overload_map__: Optional[OverloadMap] = None
|
|
91
102
|
__flex_overload_map__: Optional[OverloadMap] = None
|
|
92
|
-
__fallback_map__: Optional[
|
|
103
|
+
__fallback_map__: Optional[FuncListMap] = None
|
|
93
104
|
__finalizer_map__: Optional[FuncMap] = None
|
|
94
105
|
__plain_names__: Optional[tuple[str, ...]] = None
|
|
95
106
|
__claimed_overloads__: Optional[tuple[Claim, ...]] = None
|
|
@@ -142,18 +153,41 @@ class BaseSpace(AbstractNamespace):
|
|
|
142
153
|
"""
|
|
143
154
|
return maybe(self.__flex_overload_map__, dict())
|
|
144
155
|
|
|
145
|
-
def getFallbacks(self) ->
|
|
156
|
+
def getFallbacks(self) -> FuncListMap:
|
|
146
157
|
"""
|
|
147
|
-
The
|
|
158
|
+
The dispatchers of the class and of its subclasses need the fallbacks
|
|
159
|
+
this class body declared itself. A name may hold an instance bound
|
|
160
|
+
fallback and a class bound one together, so each name has a list.
|
|
148
161
|
|
|
149
162
|
Returns
|
|
150
163
|
-------
|
|
151
164
|
|
|
152
|
-
|
|
153
|
-
A 'dict[str, Callable]'.
|
|
165
|
+
FuncListMap
|
|
166
|
+
A 'dict[str, list[Callable]]', in declaration order.
|
|
154
167
|
"""
|
|
155
168
|
return maybe(self.__fallback_map__, dict())
|
|
156
169
|
|
|
170
|
+
def _getDeclaredFallbacks(self, name: str) -> list:
|
|
171
|
+
"""
|
|
172
|
+
A name the body declared no fallback at has none, which needs an
|
|
173
|
+
answer of its own beside the names that have.
|
|
174
|
+
|
|
175
|
+
Returns
|
|
176
|
+
-------
|
|
177
|
+
|
|
178
|
+
list
|
|
179
|
+
The fallbacks the body declared at the name, in declaration order,
|
|
180
|
+
or an empty list when it declared none.
|
|
181
|
+
"""
|
|
182
|
+
try:
|
|
183
|
+
declared = self.getFallbacks()[name]
|
|
184
|
+
except KeyError:
|
|
185
|
+
# This branch is reached by the following:
|
|
186
|
+
# - The body declared no fallback at the name
|
|
187
|
+
return []
|
|
188
|
+
else:
|
|
189
|
+
return declared
|
|
190
|
+
|
|
157
191
|
def getFinalizers(self, ) -> FuncMap:
|
|
158
192
|
"""
|
|
159
193
|
The finalizers this class body declared itself, by name.
|
|
@@ -760,8 +794,18 @@ class BaseSpace(AbstractNamespace):
|
|
|
760
794
|
|
|
761
795
|
def collectFallback(self, name: str) -> Optional[Callable]:
|
|
762
796
|
"""
|
|
763
|
-
The
|
|
764
|
-
declaring one, up to the first plain definition
|
|
797
|
+
The fallbacks of a name begin with that of the nearest class
|
|
798
|
+
declaring one, up to the first plain definition, and a namespace class
|
|
799
|
+
of a project may hand out a fallback of its own for a name by
|
|
800
|
+
reimplementing this method.
|
|
801
|
+
|
|
802
|
+
Implementation
|
|
803
|
+
--------------
|
|
804
|
+
|
|
805
|
+
The body and the namespaces from '_getInheritedSpaces' are asked in
|
|
806
|
+
order, and the fallback the first of them declared first is returned.
|
|
807
|
+
'collectFallbacks' begins with it and adds the instance bound or the
|
|
808
|
+
class bound fallback the name still lacks, when one is declared.
|
|
765
809
|
|
|
766
810
|
Parameters
|
|
767
811
|
----------
|
|
@@ -776,11 +820,64 @@ class BaseSpace(AbstractNamespace):
|
|
|
776
820
|
The fallback, or 'None'.
|
|
777
821
|
"""
|
|
778
822
|
for space in (self, *self._getInheritedSpaces(name)):
|
|
779
|
-
fallback
|
|
780
|
-
if fallback is not None:
|
|
823
|
+
for fallback in space._getDeclaredFallbacks(name):
|
|
781
824
|
return fallback
|
|
782
825
|
return None
|
|
783
826
|
|
|
827
|
+
def collectFallbacks(self, name: str) -> list:
|
|
828
|
+
"""
|
|
829
|
+
A name holding bound methods beside staticmethods is reached two
|
|
830
|
+
ways, through an instance and through the class, and a call nothing
|
|
831
|
+
accepts may need a fallback either way. The fallbacks of a name are
|
|
832
|
+
therefore two, apart: the instance bound fallback, for the calls
|
|
833
|
+
through an instance, and the class bound fallback, for the calls
|
|
834
|
+
through the class. A fallback declared as a bound method is instance
|
|
835
|
+
bound and one declared as a staticmethod is class bound, so the two
|
|
836
|
+
never answer one call and a name may hold both; one declared as a
|
|
837
|
+
classmethod is both, and stands alone. A subclass may add the one its
|
|
838
|
+
bases lack, and a fallback it declares replaces an inherited one that
|
|
839
|
+
the same call could reach. A namespace class of a project that hands
|
|
840
|
+
out a fallback of its own by reimplementing 'collectFallback' must
|
|
841
|
+
still be asked.
|
|
842
|
+
|
|
843
|
+
Implementation
|
|
844
|
+
--------------
|
|
845
|
+
|
|
846
|
+
The fallback 'collectFallback' gives comes first. The fallbacks of
|
|
847
|
+
the body and of the namespaces from '_getInheritedSpaces' follow in
|
|
848
|
+
order, each kept unless one call can reach both it and a fallback
|
|
849
|
+
gathered already, as '_mayMeet' tells by their kinds. The kinds are
|
|
850
|
+
those 'collectFunctionKinds' gives, where a function recorded nowhere
|
|
851
|
+
is a bound method.
|
|
852
|
+
|
|
853
|
+
Parameters
|
|
854
|
+
----------
|
|
855
|
+
|
|
856
|
+
name : str
|
|
857
|
+
The name.
|
|
858
|
+
|
|
859
|
+
Returns
|
|
860
|
+
-------
|
|
861
|
+
|
|
862
|
+
list
|
|
863
|
+
The fallbacks of the name, nearest first: none, one, or the
|
|
864
|
+
instance bound fallback and the class bound one.
|
|
865
|
+
"""
|
|
866
|
+
out = []
|
|
867
|
+
nearest = self.collectFallback(name)
|
|
868
|
+
if nearest is not None:
|
|
869
|
+
out.append(nearest)
|
|
870
|
+
kinds = self.collectFunctionKinds(name)
|
|
871
|
+
for space in (self, *self._getInheritedSpaces(name)):
|
|
872
|
+
for fallback in space._getDeclaredFallbacks(name):
|
|
873
|
+
own = self._kindIn(kinds, fallback)
|
|
874
|
+
for held in out:
|
|
875
|
+
if self._mayMeet(self._kindIn(kinds, held), own):
|
|
876
|
+
break
|
|
877
|
+
else:
|
|
878
|
+
out.append(fallback)
|
|
879
|
+
return out
|
|
880
|
+
|
|
784
881
|
def collectFinalizer(self, name: str) -> Optional[Callable]:
|
|
785
882
|
"""
|
|
786
883
|
As 'collectFallback', for the finalizer.
|
|
@@ -1031,8 +1128,21 @@ class BaseSpace(AbstractNamespace):
|
|
|
1031
1128
|
|
|
1032
1129
|
def addFallback(self, name: str, func: Callable) -> None:
|
|
1033
1130
|
"""
|
|
1034
|
-
|
|
1035
|
-
|
|
1131
|
+
Two fallbacks at one name leave it undecided which takes a call
|
|
1132
|
+
nothing accepts, unless no call can reach both. A fallback declared
|
|
1133
|
+
as a bound method is the instance bound fallback of its name, reached
|
|
1134
|
+
through an instance, and one declared as a staticmethod the class
|
|
1135
|
+
bound fallback, reached through the class, so a body may declare
|
|
1136
|
+
those two at one name; one declared as a classmethod is both. A
|
|
1137
|
+
subclass may replace an inherited fallback, which is not on record
|
|
1138
|
+
here.
|
|
1139
|
+
|
|
1140
|
+
Implementation
|
|
1141
|
+
--------------
|
|
1142
|
+
|
|
1143
|
+
The kind of each function is the one 'addFunctionKind' recorded for
|
|
1144
|
+
it, which 'LoadSpaceHook' records before it registers the fallback; a
|
|
1145
|
+
function recorded nowhere is a bound method.
|
|
1036
1146
|
|
|
1037
1147
|
Parameters
|
|
1038
1148
|
----------
|
|
@@ -1047,13 +1157,22 @@ class BaseSpace(AbstractNamespace):
|
|
|
1047
1157
|
------
|
|
1048
1158
|
|
|
1049
1159
|
DuplicateSignature
|
|
1050
|
-
The body declared a different fallback at the name already
|
|
1160
|
+
The body declared a different fallback at the name already, unless
|
|
1161
|
+
the two are a bound method and a staticmethod, which no call
|
|
1162
|
+
reaches together.
|
|
1051
1163
|
"""
|
|
1164
|
+
kinds = self._gatherFunctionKinds((self,), name)
|
|
1165
|
+
own = self._kindIn(kinds, func)
|
|
1052
1166
|
existing = self.getFallbacks()
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1167
|
+
held = self._getDeclaredFallbacks(name)
|
|
1168
|
+
for oldFunc in held:
|
|
1169
|
+
if oldFunc is func:
|
|
1170
|
+
break
|
|
1171
|
+
if self._mayMeet(self._kindIn(kinds, oldFunc), own):
|
|
1172
|
+
raise DuplicateSignature('fallback', oldFunc, func)
|
|
1173
|
+
else:
|
|
1174
|
+
held.append(func)
|
|
1175
|
+
existing[name] = held
|
|
1057
1176
|
self.__fallback_map__ = existing
|
|
1058
1177
|
|
|
1059
1178
|
def addFinalizer(self, name: str, func: Callable) -> None:
|
|
@@ -46,8 +46,15 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
46
46
|
the classmethods, reached through an instance, which keeps one of the
|
|
47
47
|
classmethods and the staticmethods, reached through the class. A bound
|
|
48
48
|
method is thus not considered through the class, nor a staticmethod
|
|
49
|
-
through an instance.
|
|
50
|
-
|
|
49
|
+
through an instance. Where no overload of the name is a bound method,
|
|
50
|
+
only its fallback or its finalizer, the dispatcher reached through an
|
|
51
|
+
instance holds the staticmethods as well, so a fallback takes no call
|
|
52
|
+
away from an overload. Any other name takes one dispatcher holding
|
|
53
|
+
every function. The fallbacks of a name are two, apart: the dispatcher
|
|
54
|
+
reached through an instance takes the instance bound fallback, and the
|
|
55
|
+
one reached through the class the class bound fallback. A fallback
|
|
56
|
+
declared as a bound method is the first, one declared as a
|
|
57
|
+
staticmethod the second, and one declared as a classmethod both.
|
|
51
58
|
"""
|
|
52
59
|
|
|
53
60
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
@@ -247,8 +254,11 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
247
254
|
"""
|
|
248
255
|
One name may hold bound methods, classmethods and staticmethods. A
|
|
249
256
|
bound method needs an instance, so it is not considered through the
|
|
250
|
-
class, and where a name has bound
|
|
251
|
-
considered through an instance. A classmethod is reached both
|
|
257
|
+
class, and where a name has a bound overload its staticmethods are
|
|
258
|
+
not considered through an instance. A classmethod is reached both
|
|
259
|
+
ways. A fallback or a finalizer is no overload: declaring one as a
|
|
260
|
+
bound method must take no call away from an overload that accepts
|
|
261
|
+
it.
|
|
252
262
|
|
|
253
263
|
Implementation
|
|
254
264
|
--------------
|
|
@@ -257,8 +267,10 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
257
267
|
dispatchers, each built by '_buildSide': one of the bound methods and
|
|
258
268
|
the classmethods, which is returned and reached through an instance,
|
|
259
269
|
and one of the classmethods and the staticmethods, which the first
|
|
260
|
-
keeps for a read through the class.
|
|
261
|
-
|
|
270
|
+
keeps for a read through the class. Where the bound methods of the
|
|
271
|
+
name are its fallback or its finalizer alone, the first holds the
|
|
272
|
+
staticmethods as well. Any other name takes one dispatcher of every
|
|
273
|
+
function.
|
|
262
274
|
|
|
263
275
|
Parameters
|
|
264
276
|
----------
|
|
@@ -277,7 +289,7 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
277
289
|
self.space.collectOverloads(name),
|
|
278
290
|
self.space.collectFlexes(name),
|
|
279
291
|
self.space.collectVariadics(name),
|
|
280
|
-
self.space.
|
|
292
|
+
self.space.collectFallbacks(name),
|
|
281
293
|
self.space.collectFinalizer(name),
|
|
282
294
|
)
|
|
283
295
|
members = self._getMembers(*gathered)
|
|
@@ -287,24 +299,36 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
287
299
|
memberKinds = [self.space._kindIn(kinds, func) for func in members]
|
|
288
300
|
bound = any(kind is None for kind in memberKinds)
|
|
289
301
|
other = any(kind is not None for kind in memberKinds)
|
|
302
|
+
every = (None, classmethod, staticmethod)
|
|
290
303
|
if bound and other:
|
|
291
304
|
# This branch is reached by the following:
|
|
292
305
|
# - The name holds bound methods beside classmethods or
|
|
293
306
|
# staticmethods
|
|
294
|
-
|
|
307
|
+
overloads = self._getMembers(*gathered[:3], [], None)
|
|
308
|
+
overloadKinds = [self.space._kindIn(kinds, func) for func in overloads]
|
|
309
|
+
if any(kind is None for kind in overloadKinds):
|
|
310
|
+
# This branch is reached by the following:
|
|
311
|
+
# - An overload of the name is a bound method, so its
|
|
312
|
+
# staticmethods are not considered through an instance
|
|
313
|
+
throughInstance = (None, classmethod)
|
|
314
|
+
else:
|
|
315
|
+
# This branch is reached by the following:
|
|
316
|
+
# - Only the fallback or the finalizer of the name is a bound
|
|
317
|
+
# method, which takes no call away from an overload
|
|
318
|
+
throughInstance = every
|
|
319
|
+
onInstance = self._buildSide(gathered, kinds, throughInstance)
|
|
295
320
|
onClass = self._buildSide(gathered, kinds, (classmethod, staticmethod))
|
|
296
321
|
onInstance.setClassDispatcher(onClass)
|
|
297
322
|
return onInstance
|
|
298
|
-
every = (None, classmethod, staticmethod)
|
|
299
323
|
return self._buildSide(gathered, kinds, every)
|
|
300
324
|
|
|
301
325
|
@staticmethod
|
|
302
326
|
def _getMembers(*gathered) -> list:
|
|
303
|
-
sigFuncs, flexes, variadics,
|
|
327
|
+
sigFuncs, flexes, variadics, fallbacks, finalizer = gathered
|
|
304
328
|
out = [func for _, func, __ in (*sigFuncs, *flexes, *variadics)]
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
329
|
+
out.extend(fallbacks)
|
|
330
|
+
if finalizer is not None:
|
|
331
|
+
out.append(finalizer)
|
|
308
332
|
return out
|
|
309
333
|
|
|
310
334
|
def _buildSide(
|
|
@@ -326,7 +350,12 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
326
350
|
staticmethod. The functions of another kind than that are named to it
|
|
327
351
|
by 'setFunctionKind' before any is registered, and the functions of
|
|
328
352
|
the accepted kinds are registered with their distances, the fallback
|
|
329
|
-
and the finalizer included
|
|
353
|
+
of an accepted kind and the finalizer included: the instance bound
|
|
354
|
+
fallback for the dispatcher reached through an instance, the class
|
|
355
|
+
bound fallback for the one reached through the class. A dispatcher
|
|
356
|
+
holding a fallback declared as a bound method leaves a static one to
|
|
357
|
+
the dispatcher reached through the class. A namespace handing out two
|
|
358
|
+
fallbacks for one of them is refused by the dispatcher.
|
|
330
359
|
|
|
331
360
|
Parameters
|
|
332
361
|
----------
|
|
@@ -334,8 +363,8 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
334
363
|
gathered : tuple
|
|
335
364
|
What the namespace gathered at the name: the concrete, the flexible
|
|
336
365
|
and the variadic registrations, each a list of signature, function
|
|
337
|
-
and distance, then the
|
|
338
|
-
or 'None'.
|
|
366
|
+
and distance, then the fallbacks, a list of functions, and the
|
|
367
|
+
finalizer, a function or 'None'.
|
|
339
368
|
|
|
340
369
|
kinds : list
|
|
341
370
|
A 'list[tuple[Callable, Any]]' of each function at the name with
|
|
@@ -362,12 +391,21 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
362
391
|
sigFuncs = [entry for entry in gathered[0] if taken(entry[1])]
|
|
363
392
|
flexes = [entry for entry in gathered[1] if taken(entry[1])]
|
|
364
393
|
variadics = [entry for entry in gathered[2] if taken(entry[1])]
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
394
|
+
fallbacks = [func for func in gathered[3] if taken(func)]
|
|
395
|
+
if any(kindOf(func) is None for func in fallbacks):
|
|
396
|
+
# This branch is reached by the following:
|
|
397
|
+
# - The dispatcher holds the instance bound fallback of the name,
|
|
398
|
+
# so a static one beside it is left to the dispatcher reached
|
|
399
|
+
# through the class
|
|
400
|
+
fallbacks = [
|
|
401
|
+
f for f in fallbacks
|
|
402
|
+
if kindOf(f) is classmethod or kindOf(f) is None
|
|
403
|
+
]
|
|
404
|
+
# A finalizer the name does not have is 'None' here, and stays 'None'
|
|
405
|
+
# whichever way the test falls.
|
|
368
406
|
finalizer = gathered[4] if taken(gathered[4]) else None
|
|
369
407
|
members = self._getMembers(
|
|
370
|
-
sigFuncs, flexes, variadics,
|
|
408
|
+
sigFuncs, flexes, variadics, fallbacks, finalizer,
|
|
371
409
|
)
|
|
372
410
|
memberKinds = [kindOf(func) for func in members]
|
|
373
411
|
if any(kind is None for kind in memberKinds):
|
|
@@ -389,7 +427,7 @@ class LoadSpaceHook(AbstractSpaceHook):
|
|
|
389
427
|
dispatcher.addFlexSigFunc(sig, func, distance)
|
|
390
428
|
for sig, func, distance in variadics:
|
|
391
429
|
dispatcher.addVariadicSigFunc(sig, func, distance)
|
|
392
|
-
|
|
430
|
+
for fallback in fallbacks:
|
|
393
431
|
dispatcher.setFallbackFunction(fallback)
|
|
394
432
|
if finalizer is not None:
|
|
395
433
|
dispatcher.setFinalizerFunction(finalizer)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: worktoy
|
|
3
|
-
Version: 1.2.3.
|
|
3
|
+
Version: 1.2.3.dev1
|
|
4
4
|
Summary: Declarative structure for Python that enforces types at runtime and enables true function overloading
|
|
5
5
|
Author-email: Asger Jon Vistisen <asgerjon2@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -32,7 +32,7 @@ Dynamic: license-file
|
|
|
32
32
|
[](https://pypi.org/project/worktoy/)
|
|
33
33
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
34
34
|
|
|
35
|
-
# worktoy v1.2.3-
|
|
35
|
+
# worktoy v1.2.3-dev1 (development build)
|
|
36
36
|
|
|
37
37
|
**worktoy** provides utilities for Python development focused on
|
|
38
38
|
reducing boilerplate while improving type safety and readability. Each
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
worktoy/__init__.py,sha256=
|
|
1
|
+
worktoy/__init__.py,sha256=O770D5UNsj0LEUu3zirlVrrlAP4m0gfSmI4kvZ2JxNs,2899
|
|
2
2
|
worktoy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
worktoy/core/__init__.py,sha256=dUNFlZa37R95JPn_6spjQDhI_A3LBJV34NGiyElV5gs,604
|
|
4
4
|
worktoy/core/_instance_owner.py,sha256=Nb0j0Wp8uXROUTLMVGWS_Krl6mlUcelo24vu07U4_bo,2144
|
|
@@ -28,9 +28,9 @@ worktoy/desc/_root_alias.py,sha256=t_64Ap11UQujx1Ov3eS9yOd_dUQ61hXkpXVCnHQOfKw,4
|
|
|
28
28
|
worktoy/desc/_symbolic_name.py,sha256=KPtQtU-5GWv7C0xK8wpn7x6zTbMVJEPKLJW7LYjt_sM,6133
|
|
29
29
|
worktoy/dispatch/__init__.py,sha256=VcWtjDBdeUhEcPK7LH4-4Ok484kTAXRqC0lXZEZWfJM,1134
|
|
30
30
|
worktoy/dispatch/_call_me_maybe.py,sha256=w1RXd_yi1TdCIL-Ee5FYmNBYC_2mHV8TNUZxnAPi2oc,7666
|
|
31
|
-
worktoy/dispatch/_dispatcher.py,sha256=
|
|
31
|
+
worktoy/dispatch/_dispatcher.py,sha256=Ni1YeHgQaKTIR-qsy9ITuhWbjy2opM9pChLZyKt87oU,57893
|
|
32
32
|
worktoy/dispatch/_flex_call.py,sha256=lz7e0Wa36ejNzrFzH9Dmd-f5yVqN1WbCAelKYNanPiw,4632
|
|
33
|
-
worktoy/dispatch/_overload.py,sha256=
|
|
33
|
+
worktoy/dispatch/_overload.py,sha256=OPBUkXaw-YDtzK5x7h1Y7NFYzM-UKMQKXv9cOh4etkM,26795
|
|
34
34
|
worktoy/dispatch/_permuter.py,sha256=n8mNyViyn5gIBRjRjtq438Qb0GC7R3XXy59Eu_MJq6I,8172
|
|
35
35
|
worktoy/dispatch/_permuter_method.py,sha256=N_KquUeKxWjfAruY7pVmAWzjPLYsTDAMlwnllMiT9nA,1657
|
|
36
36
|
worktoy/dispatch/_type_sig.py,sha256=XZFOuPjsqrhtxQWjM9wqTAxVHGHKBo5dsjbQhu81qhM,15160
|
|
@@ -70,11 +70,11 @@ worktoy/mcls/_abstract_metaclass.py,sha256=ntkgG-RojlThddvTx9D-5zT-Oq-wQVu33uTr-
|
|
|
70
70
|
worktoy/mcls/_abstract_namespace.py,sha256=WayJ-mG248nT5sV4e0G6PGkk_-CpxKKsz-ML4ub6qxw,18782
|
|
71
71
|
worktoy/mcls/_base_meta.py,sha256=kRoLGaqIu5OvraSG_TdBCKpoMDr4q8D_cUH81BhZgjY,1119
|
|
72
72
|
worktoy/mcls/_base_object.py,sha256=nmn62F_PmVDURIBdAeW6U2lNVJdn0w_pc-LUDRKa3ls,2138
|
|
73
|
-
worktoy/mcls/_base_space.py,sha256=
|
|
73
|
+
worktoy/mcls/_base_space.py,sha256=jUka-0aAac5t-BVLpkpK79rbxKDv3v-gfBfZTQk8uMQ,37025
|
|
74
74
|
worktoy/mcls/space_hooks/__init__.py,sha256=h2m1uKEcPsprkcg0Cw3g3tDOHM7jKgcsr0Hs-b0AYdA,1180
|
|
75
75
|
worktoy/mcls/space_hooks/_abstract_space_hook.py,sha256=QUpoorQJbZhEn_XbEK106ZNijns5deOoh-oKKT2aYEU,7158
|
|
76
76
|
worktoy/mcls/space_hooks/_flex_call_hook.py,sha256=FfKFuKnvY-PuLu8CFfyz_hzjd6T0dbxDA2tHK5nVvcA,1126
|
|
77
|
-
worktoy/mcls/space_hooks/_load_space_hook.py,sha256=
|
|
77
|
+
worktoy/mcls/space_hooks/_load_space_hook.py,sha256=2SRHhstEHBBrtouLPW4McCtxMf8-FP5EI149PON1ftE,16032
|
|
78
78
|
worktoy/mcls/space_hooks/_name_hook.py,sha256=tItAB5rs5wFknhjYG-LrpOFlO1bvGILio5ThsAJ1DfE,12675
|
|
79
79
|
worktoy/mcls/space_hooks/_reserved_names.py,sha256=siKNcEalYATzzUhngcnDfcnFWng-I5cIoRc7XctuUDI,1359
|
|
80
80
|
worktoy/mcls/space_hooks/_reserved_namespace_hook.py,sha256=DVHMNdbK-lnJp6IdThP2yYEmqDcBFGBBYdhn2i5vsQ4,1800
|
|
@@ -194,8 +194,8 @@ worktoy/work_test/samplers/_lorem_text.py,sha256=KQgBKQ5iLS_lU7HGvfoLTVsFyDcm-JR
|
|
|
194
194
|
worktoy/work_test/samplers/_sampler_meta.py,sha256=9AodXKw3Ww-Eu1qzqJsRm-AbYolgON9TKA5fdfBZ9bY,1216
|
|
195
195
|
worktoy/work_test/samplers/_symbolic_sampler.py,sha256=VgheImGi_-WiUYa1o-Htu1OSjoOqTzx8PycDzf-es4c,3042
|
|
196
196
|
worktoy/work_test/samplers/_word_sampler.py,sha256=9K5ib8Wt2APUEMh2ZGMRNSkHjnUpl_HDl8OdFSgw1BU,1044
|
|
197
|
-
worktoy-1.2.3.
|
|
198
|
-
worktoy-1.2.3.
|
|
199
|
-
worktoy-1.2.3.
|
|
200
|
-
worktoy-1.2.3.
|
|
201
|
-
worktoy-1.2.3.
|
|
197
|
+
worktoy-1.2.3.dev1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
198
|
+
worktoy-1.2.3.dev1.dist-info/METADATA,sha256=XuN16jK2rYmwiIuECXDUcuFEbTsySXcYkqiR1B-4s3I,10656
|
|
199
|
+
worktoy-1.2.3.dev1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
200
|
+
worktoy-1.2.3.dev1.dist-info/top_level.txt,sha256=6yO8xnr7WakfINq91qO3rs5ECubDOGvAQ9ztVgoG0j4,8
|
|
201
|
+
worktoy-1.2.3.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|