datahold 4.0.0.dev7__tar.gz → 4.0.0.dev9__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.
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/PKG-INFO +1 -1
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/pyproject.toml +1 -1
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/src/datahold/__init__.py +82 -79
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/src/datahold.egg-info/PKG-INFO +1 -1
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/tests/test_FrozenHoldDict.py +3 -3
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/tests/test_FrozenHoldList.py +3 -3
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/tests/test_FrozenHoldSet.py +3 -3
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/tests/test_HoldDict.py +3 -3
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/tests/test_HoldList.py +3 -3
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/tests/test_HoldSet.py +3 -3
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/tests/test_testdata.py +13 -11
- datahold-4.0.0.dev9/tests/testdata.toml +145 -0
- datahold-4.0.0.dev7/tests/testdata.toml +0 -136
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/LICENSE.txt +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/MANIFEST.in +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/README.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v1.1.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v1.2.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v2.0.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v2.1.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v2.2.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v2.3.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v3.0.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/docs/v4.0.rst +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/run_tests.py +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/setup.cfg +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/src/datahold/py.typed +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/src/datahold.egg-info/SOURCES.txt +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/src/datahold.egg-info/dependency_links.txt +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/src/datahold.egg-info/requires.txt +0 -0
- {datahold-4.0.0.dev7 → datahold-4.0.0.dev9}/src/datahold.egg-info/top_level.txt +0 -0
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
__all__: list[str] = [
|
|
6
|
-
"BaseDataAbstractSet",
|
|
7
|
-
"BaseDataCollection",
|
|
8
|
-
"BaseDataDict",
|
|
9
|
-
"BaseDataList",
|
|
10
|
-
"BaseDataMapping",
|
|
11
|
-
"BaseDataSequence",
|
|
12
|
-
"BaseDataSet",
|
|
13
6
|
"BaseHoldObject",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
7
|
+
"Collection",
|
|
8
|
+
"DictLike",
|
|
9
|
+
"FrozenDictLike",
|
|
10
|
+
"FrozenListLike",
|
|
11
|
+
"FrozenMapping",
|
|
12
|
+
"FrozenSetLike",
|
|
13
|
+
"ListLike",
|
|
14
|
+
"Mapping",
|
|
15
|
+
"MutableDictLike",
|
|
16
|
+
"MutableListLike",
|
|
17
|
+
"MutableSetLike",
|
|
18
|
+
"Sequence",
|
|
19
|
+
"Set",
|
|
20
|
+
"SetLike",
|
|
20
21
|
]
|
|
21
22
|
|
|
22
23
|
import enum
|
|
@@ -80,7 +81,7 @@ class BaseHoldObject[HoldData: Copyable]:
|
|
|
80
81
|
### COLLECTION ###
|
|
81
82
|
|
|
82
83
|
|
|
83
|
-
class
|
|
84
|
+
class Collection[Item](
|
|
84
85
|
abc.Sized,
|
|
85
86
|
abc.Iterable[Item],
|
|
86
87
|
abc.Container[object],
|
|
@@ -106,6 +107,10 @@ class BaseDataCollection[Item](
|
|
|
106
107
|
except TypeError:
|
|
107
108
|
return other in (x for x in self.__fget__()) # type: ignore[operator]
|
|
108
109
|
|
|
110
|
+
@abstractmethod
|
|
111
|
+
@setdoc.basic
|
|
112
|
+
def __fget__(self: Self) -> Data[Item]: ...
|
|
113
|
+
|
|
109
114
|
@setdoc.basic
|
|
110
115
|
def __iter__(self: Self, /) -> abc.Iterator[Item]:
|
|
111
116
|
return iter(self.__fget__())
|
|
@@ -114,16 +119,12 @@ class BaseDataCollection[Item](
|
|
|
114
119
|
def __len__(self: Self, /) -> int:
|
|
115
120
|
return len(self.__fget__())
|
|
116
121
|
|
|
117
|
-
@abstractmethod
|
|
118
|
-
@setdoc.basic
|
|
119
|
-
def __fget__(self: Self) -> Data[Item]: ...
|
|
120
|
-
|
|
121
122
|
|
|
122
123
|
### ABSTRACT SET ###
|
|
123
124
|
|
|
124
125
|
|
|
125
|
-
class
|
|
126
|
-
|
|
126
|
+
class Set[Item](
|
|
127
|
+
Collection[Item],
|
|
127
128
|
abc.Set[Item],
|
|
128
129
|
):
|
|
129
130
|
"""Provide an easy abc for a custom (abstract) set."""
|
|
@@ -134,7 +135,7 @@ class BaseDataAbstractSet[Item](
|
|
|
134
135
|
### SET ###
|
|
135
136
|
|
|
136
137
|
|
|
137
|
-
class
|
|
138
|
+
class SetLike[Item: abc.Hashable](Set[Item]):
|
|
138
139
|
"""Provide an easy abc for custom set-like."""
|
|
139
140
|
|
|
140
141
|
__slots__ = ()
|
|
@@ -189,7 +190,7 @@ class BaseDataSet[Item: abc.Hashable](BaseDataAbstractSet[Item]):
|
|
|
189
190
|
return type(self)(self.__fget__().union(*others))
|
|
190
191
|
|
|
191
192
|
|
|
192
|
-
class
|
|
193
|
+
class FrozenSetLike[Item: abc.Hashable](SetLike[Item], abc.Hashable):
|
|
193
194
|
"""Provide easy abc for custom frozen set-like."""
|
|
194
195
|
|
|
195
196
|
__slots__ = ()
|
|
@@ -199,8 +200,8 @@ class FrozenDataSet[Item: abc.Hashable](BaseDataSet[Item], abc.Hashable):
|
|
|
199
200
|
return hash(frozenset(self.__fget__()))
|
|
200
201
|
|
|
201
202
|
|
|
202
|
-
class
|
|
203
|
-
|
|
203
|
+
class MutableSetLike[Item: abc.Hashable](
|
|
204
|
+
SetLike[Item],
|
|
204
205
|
abc.MutableSet[Item],
|
|
205
206
|
):
|
|
206
207
|
"""Provide easy abc for custom mutable set-like."""
|
|
@@ -209,7 +210,10 @@ class DataSet[Item: abc.Hashable](
|
|
|
209
210
|
|
|
210
211
|
@setdoc.basic
|
|
211
212
|
def add(self: Self, item: Item, /) -> None:
|
|
212
|
-
|
|
213
|
+
data: set[Item]
|
|
214
|
+
data = self.__fget__()
|
|
215
|
+
data.add(item)
|
|
216
|
+
self.__fset__(data)
|
|
213
217
|
|
|
214
218
|
@setdoc.basic
|
|
215
219
|
def copy(self: Self) -> Self:
|
|
@@ -221,10 +225,7 @@ class DataSet[Item: abc.Hashable](
|
|
|
221
225
|
/,
|
|
222
226
|
*others: abc.Iterable[abc.Hashable],
|
|
223
227
|
) -> None:
|
|
224
|
-
|
|
225
|
-
data = self.__fget__()
|
|
226
|
-
data.difference_update(*others)
|
|
227
|
-
self.__fset__(data)
|
|
228
|
+
self.__fset__(self.__fget__().difference(*others))
|
|
228
229
|
|
|
229
230
|
@setdoc.basic
|
|
230
231
|
def discard(self: Self, item: abc.Hashable, /) -> None:
|
|
@@ -237,19 +238,13 @@ class DataSet[Item: abc.Hashable](
|
|
|
237
238
|
def intersection_update(
|
|
238
239
|
self: Self, /, *others: abc.Iterable[abc.Hashable]
|
|
239
240
|
) -> None:
|
|
240
|
-
|
|
241
|
-
data = self.__fget__()
|
|
242
|
-
data.intersection_update(*others)
|
|
243
|
-
self.__fset__(data)
|
|
241
|
+
self.__fset__(self.__fget__().intersection(*others))
|
|
244
242
|
|
|
245
243
|
@setdoc.basic
|
|
246
244
|
def symmetric_difference_update(
|
|
247
245
|
self: Self, other: abc.Iterable[Item], /
|
|
248
246
|
) -> None:
|
|
249
|
-
|
|
250
|
-
data = self.__fget__()
|
|
251
|
-
data.symmetric_difference_update(other)
|
|
252
|
-
self.__fset__(data)
|
|
247
|
+
self.__fset__(self.__fget__().symmetric_difference(other))
|
|
253
248
|
|
|
254
249
|
@setdoc.basic
|
|
255
250
|
def update(self: Self, /, *others: abc.Iterable[Item]) -> None:
|
|
@@ -257,8 +252,8 @@ class DataSet[Item: abc.Hashable](
|
|
|
257
252
|
|
|
258
253
|
|
|
259
254
|
### MAPPING ###
|
|
260
|
-
class
|
|
261
|
-
|
|
255
|
+
class Mapping[Key: abc.Hashable, Value](
|
|
256
|
+
Collection[Key], abc.Mapping[Key, Value]
|
|
262
257
|
):
|
|
263
258
|
"""Provide an easy abc for a custom mapping."""
|
|
264
259
|
|
|
@@ -266,12 +261,15 @@ class BaseDataMapping[Key, Value](
|
|
|
266
261
|
|
|
267
262
|
@setdoc.basic
|
|
268
263
|
class Data[DataKey, DataValue](
|
|
269
|
-
|
|
264
|
+
Collection.Data[DataKey],
|
|
270
265
|
Protocol,
|
|
271
266
|
):
|
|
272
267
|
@setdoc.basic
|
|
273
|
-
def __getitem__(self: Self, key: Never, /) -> DataValue:
|
|
274
|
-
|
|
268
|
+
def __getitem__(self: Self, key: Never, /) -> DataValue: ...
|
|
269
|
+
|
|
270
|
+
@abstractmethod
|
|
271
|
+
@setdoc.basic
|
|
272
|
+
def __fget__(self: Self) -> Data[Key, Value]: ...
|
|
275
273
|
|
|
276
274
|
@setdoc.basic
|
|
277
275
|
def __getitem__(self: Self, key: object, /) -> Value:
|
|
@@ -280,16 +278,25 @@ class BaseDataMapping[Key, Value](
|
|
|
280
278
|
except TypeError:
|
|
281
279
|
raise KeyError(key) from None
|
|
282
280
|
|
|
283
|
-
|
|
281
|
+
|
|
282
|
+
class FrozenMapping[Key: abc.Hashable, Value](
|
|
283
|
+
Mapping[Key, Value],
|
|
284
|
+
abc.Hashable,
|
|
285
|
+
):
|
|
286
|
+
"""Provide an easy abc for a custom frozen mapping."""
|
|
287
|
+
|
|
288
|
+
__slots__ = ()
|
|
289
|
+
|
|
284
290
|
@setdoc.basic
|
|
285
|
-
def
|
|
291
|
+
def __hash__(self: Self) -> int:
|
|
292
|
+
return hash(frozendict(self.items()))
|
|
286
293
|
|
|
287
294
|
|
|
288
295
|
### DICT ###
|
|
289
296
|
|
|
290
297
|
|
|
291
|
-
class
|
|
292
|
-
|
|
298
|
+
class DictLike[Key: abc.Hashable, Value](
|
|
299
|
+
Mapping[Key | str, Optional[Value]],
|
|
293
300
|
):
|
|
294
301
|
"""Provide an easy abc for custom dict-like."""
|
|
295
302
|
|
|
@@ -316,7 +323,7 @@ class BaseDataDict[Key: abc.Hashable, Value](
|
|
|
316
323
|
/,
|
|
317
324
|
**kwargs: Optional[Value],
|
|
318
325
|
) -> None:
|
|
319
|
-
data_:
|
|
326
|
+
data_: DictLike.Data[Key, Value]
|
|
320
327
|
data_ = dict( # type: ignore[assignment]
|
|
321
328
|
data, # type: ignore[arg-type]
|
|
322
329
|
**kwargs,
|
|
@@ -326,7 +333,7 @@ class BaseDataDict[Key: abc.Hashable, Value](
|
|
|
326
333
|
@setdoc.basic
|
|
327
334
|
def __or__(
|
|
328
335
|
self: Self,
|
|
329
|
-
other:
|
|
336
|
+
other: DictLike[Key, Value],
|
|
330
337
|
/,
|
|
331
338
|
) -> Self:
|
|
332
339
|
return type(self)(self.__fget__() | other.__fget__())
|
|
@@ -348,21 +355,17 @@ class BaseDataDict[Key: abc.Hashable, Value](
|
|
|
348
355
|
return cls(dict.fromkeys(iterable, value))
|
|
349
356
|
|
|
350
357
|
|
|
351
|
-
class
|
|
352
|
-
|
|
353
|
-
|
|
358
|
+
class FrozenDictLike[Key: abc.Hashable, Value](
|
|
359
|
+
DictLike[Key, Value],
|
|
360
|
+
FrozenMapping[Key | str, Optional[Value]],
|
|
354
361
|
):
|
|
355
362
|
"""Provide easy abc for custom frozen dict-like."""
|
|
356
363
|
|
|
357
364
|
__slots__ = ()
|
|
358
365
|
|
|
359
|
-
@setdoc.basic
|
|
360
|
-
def __hash__(self: Self) -> int:
|
|
361
|
-
return hash(frozendict(self.__fget__()))
|
|
362
|
-
|
|
363
366
|
|
|
364
|
-
class
|
|
365
|
-
|
|
367
|
+
class MutableDictLike[Key: abc.Hashable, Value](
|
|
368
|
+
DictLike[Key, Value],
|
|
366
369
|
abc.MutableMapping[Key | str, Optional[Value]],
|
|
367
370
|
):
|
|
368
371
|
"""Provide easy abc for custom mutable dict-like."""
|
|
@@ -371,7 +374,7 @@ class DataDict[Key: abc.Hashable, Value](
|
|
|
371
374
|
|
|
372
375
|
@setdoc.basic
|
|
373
376
|
def __delitem__(self: Self, key: Key | str, /) -> None:
|
|
374
|
-
data:
|
|
377
|
+
data: MutableDictLike.Data[Key, Value]
|
|
375
378
|
data = self.__fget__()
|
|
376
379
|
del data[key]
|
|
377
380
|
self.__fset__(data)
|
|
@@ -379,7 +382,7 @@ class DataDict[Key: abc.Hashable, Value](
|
|
|
379
382
|
@setdoc.basic
|
|
380
383
|
def __ior__(
|
|
381
384
|
self: Self,
|
|
382
|
-
other:
|
|
385
|
+
other: DictLike[Key, Value],
|
|
383
386
|
/,
|
|
384
387
|
) -> Self:
|
|
385
388
|
self.__fset__(self.__fget__() | other.__fget__())
|
|
@@ -393,7 +396,7 @@ class DataDict[Key: abc.Hashable, Value](
|
|
|
393
396
|
/,
|
|
394
397
|
) -> None:
|
|
395
398
|
# what to do if Key includes unhashable types?
|
|
396
|
-
data:
|
|
399
|
+
data: MutableDictLike.Data[Key, Value]
|
|
397
400
|
data = self.__fget__()
|
|
398
401
|
data[key] = value
|
|
399
402
|
self.__fset__(data)
|
|
@@ -406,8 +409,8 @@ class DataDict[Key: abc.Hashable, Value](
|
|
|
406
409
|
### SEQUENCE ###
|
|
407
410
|
|
|
408
411
|
|
|
409
|
-
class
|
|
410
|
-
|
|
412
|
+
class Sequence[Item](
|
|
413
|
+
Collection[Item],
|
|
411
414
|
abc.Sequence[Item],
|
|
412
415
|
):
|
|
413
416
|
"""Provide an easy abc for a custom sequence."""
|
|
@@ -416,7 +419,7 @@ class BaseDataSequence[Item](
|
|
|
416
419
|
|
|
417
420
|
@setdoc.basic
|
|
418
421
|
class Data[DataItem](
|
|
419
|
-
|
|
422
|
+
Collection.Data[DataItem],
|
|
420
423
|
Protocol,
|
|
421
424
|
):
|
|
422
425
|
"""Provide sequence data protocol."""
|
|
@@ -434,6 +437,10 @@ class BaseDataSequence[Item](
|
|
|
434
437
|
self: Self, key: int | Slice[int], /
|
|
435
438
|
) -> DataItem | abc.Sequence[DataItem]: ...
|
|
436
439
|
|
|
440
|
+
@abstractmethod
|
|
441
|
+
@setdoc.basic
|
|
442
|
+
def __fget__(self: Self) -> Data[Item]: ...
|
|
443
|
+
|
|
437
444
|
@overload
|
|
438
445
|
@setdoc.basic
|
|
439
446
|
def __getitem__(self: Self, key: int, /) -> Item: ...
|
|
@@ -446,15 +453,11 @@ class BaseDataSequence[Item](
|
|
|
446
453
|
) -> Item | abc.Sequence[Item]:
|
|
447
454
|
return self.__fget__()[key]
|
|
448
455
|
|
|
449
|
-
@abstractmethod
|
|
450
|
-
@setdoc.basic
|
|
451
|
-
def __fget__(self: Self) -> Data[Item]: ...
|
|
452
|
-
|
|
453
456
|
|
|
454
457
|
### LIST ###
|
|
455
458
|
|
|
456
459
|
|
|
457
|
-
class
|
|
460
|
+
class ListLike[Item](Sequence[Item]):
|
|
458
461
|
"""Provide an easy abc for custom list-like."""
|
|
459
462
|
|
|
460
463
|
__slots__ = ()
|
|
@@ -463,7 +466,7 @@ class BaseDataList[Item](BaseDataSequence[Item]):
|
|
|
463
466
|
type Init[InitItem] = abc.Iterable[InitItem]
|
|
464
467
|
|
|
465
468
|
@setdoc.basic
|
|
466
|
-
def __add__(self: Self, other:
|
|
469
|
+
def __add__(self: Self, other: ListLike[Item], /) -> Self:
|
|
467
470
|
# list.__add__ reveals Overload(
|
|
468
471
|
# def [_T] (list[_T], list[_T]) -> list[_T],
|
|
469
472
|
# def [_T, _S] (list[_T], list[_S]) -> list[_S | _T],
|
|
@@ -472,14 +475,14 @@ class BaseDataList[Item](BaseDataSequence[Item]):
|
|
|
472
475
|
# def [_T_co] (tuple[_T_co, ...], tuple[_T_co, ...]) -> tuple[_T_co, ...],
|
|
473
476
|
# def [_T_co, _T] (tuple[_T_co, ...], tuple[_T, ...]) -> tuple[_T_co | _T, ...],
|
|
474
477
|
# )
|
|
475
|
-
if isinstance(other,
|
|
478
|
+
if isinstance(other, ListLike):
|
|
476
479
|
return type(self)(self.__fget__() + other.__fget__())
|
|
477
480
|
else:
|
|
478
481
|
return NotImplemented
|
|
479
482
|
|
|
480
483
|
@setdoc.basic
|
|
481
484
|
def __eq__(self: Self, other: object, /) -> NotImplementedType | bool:
|
|
482
|
-
if isinstance(other,
|
|
485
|
+
if isinstance(other, ListLike):
|
|
483
486
|
return self.__fget__() == other.__fget__()
|
|
484
487
|
else:
|
|
485
488
|
return NotImplemented
|
|
@@ -494,7 +497,7 @@ class BaseDataList[Item](BaseDataSequence[Item]):
|
|
|
494
497
|
|
|
495
498
|
@setdoc.basic
|
|
496
499
|
def __ge__(self: Self, other: object, /) -> NotImplementedType | bool:
|
|
497
|
-
if isinstance(other,
|
|
500
|
+
if isinstance(other, ListLike):
|
|
498
501
|
return self.__fget__() >= other.__fget__()
|
|
499
502
|
else:
|
|
500
503
|
return NotImplemented
|
|
@@ -518,7 +521,7 @@ class BaseDataList[Item](BaseDataSequence[Item]):
|
|
|
518
521
|
|
|
519
522
|
@setdoc.basic
|
|
520
523
|
def __gt__(self: Self, other: object, /) -> NotImplementedType | bool:
|
|
521
|
-
if isinstance(other,
|
|
524
|
+
if isinstance(other, ListLike):
|
|
522
525
|
return self.__fget__() > other.__fget__()
|
|
523
526
|
else:
|
|
524
527
|
return NotImplemented
|
|
@@ -529,14 +532,14 @@ class BaseDataList[Item](BaseDataSequence[Item]):
|
|
|
529
532
|
|
|
530
533
|
@setdoc.basic
|
|
531
534
|
def __le__(self: Self, other: object, /) -> NotImplementedType | bool:
|
|
532
|
-
if isinstance(other,
|
|
535
|
+
if isinstance(other, ListLike):
|
|
533
536
|
return self.__fget__() <= other.__fget__()
|
|
534
537
|
else:
|
|
535
538
|
return NotImplemented
|
|
536
539
|
|
|
537
540
|
@setdoc.basic
|
|
538
541
|
def __lt__(self: Self, other: object, /) -> NotImplementedType | bool:
|
|
539
|
-
if isinstance(other,
|
|
542
|
+
if isinstance(other, ListLike):
|
|
540
543
|
return self.__fget__() < other.__fget__()
|
|
541
544
|
else:
|
|
542
545
|
return NotImplemented
|
|
@@ -552,8 +555,8 @@ class BaseDataList[Item](BaseDataSequence[Item]):
|
|
|
552
555
|
__rmul__ = __mul__
|
|
553
556
|
|
|
554
557
|
|
|
555
|
-
class
|
|
556
|
-
|
|
558
|
+
class FrozenListLike[Item](
|
|
559
|
+
ListLike[Item],
|
|
557
560
|
abc.Hashable,
|
|
558
561
|
):
|
|
559
562
|
"""Provide easy abc for custom frozen list-like."""
|
|
@@ -565,8 +568,8 @@ class FrozenDataList[Item](
|
|
|
565
568
|
return hash(tuple(self.__fget__()))
|
|
566
569
|
|
|
567
570
|
|
|
568
|
-
class
|
|
569
|
-
|
|
571
|
+
class MutableListLike[Item](
|
|
572
|
+
ListLike[Item],
|
|
570
573
|
abc.MutableSequence[Item],
|
|
571
574
|
):
|
|
572
575
|
"""Provide easy abc for custom mutable list-like."""
|
|
@@ -11,12 +11,12 @@ from typing import Any, Self
|
|
|
11
11
|
|
|
12
12
|
from frozendict import frozendict
|
|
13
13
|
|
|
14
|
-
from datahold import BaseHoldObject,
|
|
14
|
+
from datahold import BaseHoldObject, FrozenDictLike
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class FrozenHoldDict[Key: abc.Hashable, Value](
|
|
18
|
-
BaseHoldObject[
|
|
19
|
-
|
|
18
|
+
BaseHoldObject[FrozenDictLike.Data[Key, Value]],
|
|
19
|
+
FrozenDictLike[Key, Value],
|
|
20
20
|
):
|
|
21
21
|
"""Provide usable frozen dict-like with slots."""
|
|
22
22
|
|
|
@@ -7,12 +7,12 @@ __all__: list[str] = [
|
|
|
7
7
|
import unittest
|
|
8
8
|
from typing import Any, Self
|
|
9
9
|
|
|
10
|
-
from datahold import BaseHoldObject,
|
|
10
|
+
from datahold import BaseHoldObject, FrozenListLike
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class FrozenHoldList[Item](
|
|
14
|
-
BaseHoldObject[
|
|
15
|
-
|
|
14
|
+
BaseHoldObject[FrozenListLike.Data[Item]],
|
|
15
|
+
FrozenListLike[Item],
|
|
16
16
|
):
|
|
17
17
|
"""Provide usable frozen list-like with slots."""
|
|
18
18
|
|
|
@@ -8,12 +8,12 @@ import unittest
|
|
|
8
8
|
from collections import abc
|
|
9
9
|
from typing import Any, Self
|
|
10
10
|
|
|
11
|
-
from datahold import BaseHoldObject,
|
|
11
|
+
from datahold import BaseHoldObject, FrozenSetLike
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class FrozenHoldSet[Item: abc.Hashable](
|
|
15
|
-
BaseHoldObject[
|
|
16
|
-
|
|
15
|
+
BaseHoldObject[FrozenSetLike.Data[Item]],
|
|
16
|
+
FrozenSetLike[Item],
|
|
17
17
|
):
|
|
18
18
|
"""Provide usable frozen set-like with slots."""
|
|
19
19
|
|
|
@@ -8,12 +8,12 @@ import unittest
|
|
|
8
8
|
from collections import abc
|
|
9
9
|
from typing import Any, Self, cast
|
|
10
10
|
|
|
11
|
-
from datahold import BaseHoldObject,
|
|
11
|
+
from datahold import BaseHoldObject, MutableDictLike
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class HoldDict[Key: abc.Hashable, Value](
|
|
15
|
-
BaseHoldObject[
|
|
16
|
-
|
|
15
|
+
BaseHoldObject[MutableDictLike.Data[Key, Value]],
|
|
16
|
+
MutableDictLike[Key, Value],
|
|
17
17
|
):
|
|
18
18
|
"""Provide usable mutable dict-like with slots."""
|
|
19
19
|
|
|
@@ -7,12 +7,12 @@ __all__: list[str] = [
|
|
|
7
7
|
import unittest
|
|
8
8
|
from typing import Any, Self
|
|
9
9
|
|
|
10
|
-
from datahold import BaseHoldObject,
|
|
10
|
+
from datahold import BaseHoldObject, MutableListLike
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class HoldList[Item](
|
|
14
|
-
BaseHoldObject[
|
|
15
|
-
|
|
14
|
+
BaseHoldObject[MutableListLike.Data[Item]],
|
|
15
|
+
MutableListLike[Item],
|
|
16
16
|
):
|
|
17
17
|
"""Provide usable mutable list-like with slots."""
|
|
18
18
|
|
|
@@ -8,12 +8,12 @@ import unittest
|
|
|
8
8
|
from collections import abc
|
|
9
9
|
from typing import Any, Self
|
|
10
10
|
|
|
11
|
-
from datahold import BaseHoldObject,
|
|
11
|
+
from datahold import BaseHoldObject, MutableSetLike
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class HoldSet[Item: abc.Hashable](
|
|
15
|
-
BaseHoldObject[
|
|
16
|
-
|
|
15
|
+
BaseHoldObject[MutableSetLike.Data[Item]],
|
|
16
|
+
MutableSetLike[Item],
|
|
17
17
|
):
|
|
18
18
|
"""Provide usable mutable set-like with slots."""
|
|
19
19
|
|
|
@@ -17,6 +17,7 @@ import io
|
|
|
17
17
|
import tomllib
|
|
18
18
|
import unittest
|
|
19
19
|
from functools import cached_property
|
|
20
|
+
from importlib import import_module
|
|
20
21
|
from pathlib import Path
|
|
21
22
|
from typing import Any, Self, TypeAliasType, cast, get_args, get_origin
|
|
22
23
|
|
|
@@ -42,14 +43,17 @@ class Lazy(enum.Enum):
|
|
|
42
43
|
with file.open("rb") as stream:
|
|
43
44
|
return tomllib.load(stream)
|
|
44
45
|
|
|
46
|
+
@classmethod
|
|
47
|
+
def get_import(cls: type[Self], qualname: str) -> type[Any]:
|
|
48
|
+
module: Any
|
|
49
|
+
parts: list[str]
|
|
50
|
+
parts = qualname.split(".")
|
|
51
|
+
module = import_module(".".join(parts[:-1]))
|
|
52
|
+
return cast(type[Any], getattr(module, parts[-1]))
|
|
53
|
+
|
|
45
54
|
@classmethod
|
|
46
55
|
def get_type(cls: type[Self], typename: str) -> type[Any]:
|
|
47
|
-
|
|
48
|
-
if typename in collections.abc.__all__:
|
|
49
|
-
ans = getattr(collections.abc, typename)
|
|
50
|
-
else:
|
|
51
|
-
ans = getattr(datahold, typename)
|
|
52
|
-
return cast(type[Any], ans)
|
|
56
|
+
return cast(type[Any], getattr(datahold, typename))
|
|
53
57
|
|
|
54
58
|
@cached_property
|
|
55
59
|
def test_object(self: Self) -> dict[str, Any]:
|
|
@@ -102,8 +106,6 @@ class TestCollection(unittest.TestCase):
|
|
|
102
106
|
typename: str
|
|
103
107
|
for typename in Lazy.lazy.types.keys():
|
|
104
108
|
cls = Lazy.get_type(typename=typename)
|
|
105
|
-
if cls is None:
|
|
106
|
-
raise Exception
|
|
107
109
|
self._test_cls(cls)
|
|
108
110
|
|
|
109
111
|
|
|
@@ -133,7 +135,7 @@ class TestConstructor(unittest.TestCase):
|
|
|
133
135
|
self.assertIn(info.get("repr"), [None, repr(obj)])
|
|
134
136
|
self.assertIn(info.get("str"), [None, str(obj)])
|
|
135
137
|
for x, y in info.get("parents", {}).items():
|
|
136
|
-
parenttype = Lazy.
|
|
138
|
+
parenttype = Lazy.get_import(x)
|
|
137
139
|
self.assertEqual(isinstance(obj, parenttype), y)
|
|
138
140
|
|
|
139
141
|
def go_types(self: Self, typename: str, /, **kwargs: Any) -> None:
|
|
@@ -147,7 +149,7 @@ class TestConstructor(unittest.TestCase):
|
|
|
147
149
|
|
|
148
150
|
def test_abstract_classes(self: Self) -> None:
|
|
149
151
|
for typename, kwargs in Lazy.lazy.types.items():
|
|
150
|
-
with self.subTest(
|
|
152
|
+
with self.subTest(type=typename):
|
|
151
153
|
self.go_types(typename, **kwargs)
|
|
152
154
|
|
|
153
155
|
|
|
@@ -303,7 +305,7 @@ class TestParents(unittest.TestCase):
|
|
|
303
305
|
if cls is None:
|
|
304
306
|
raise Exception
|
|
305
307
|
for x, y in kwargs.get("parents", {}).items():
|
|
306
|
-
parenttype = Lazy.
|
|
308
|
+
parenttype = Lazy.get_import(x)
|
|
307
309
|
self.assertEqual(issubclass(cls, parenttype), y, x)
|
|
308
310
|
|
|
309
311
|
def test_parents(self: Self) -> None:
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
[test_object]
|
|
2
|
+
METHODS = [
|
|
3
|
+
"__format__",
|
|
4
|
+
"__str__",
|
|
5
|
+
]
|
|
6
|
+
|
|
7
|
+
[types.Collection]
|
|
8
|
+
dirData = [
|
|
9
|
+
"__contains__",
|
|
10
|
+
"__iter__",
|
|
11
|
+
"__len__",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[types.Collection.parents]
|
|
15
|
+
"collections.abc.Collection" = true
|
|
16
|
+
"collections.abc.Hashable" = true
|
|
17
|
+
|
|
18
|
+
[types.DictLike]
|
|
19
|
+
dirData = []
|
|
20
|
+
|
|
21
|
+
[types.DictLike.parents]
|
|
22
|
+
"collections.abc.Hashable" = false
|
|
23
|
+
"collections.abc.Mapping" = true
|
|
24
|
+
|
|
25
|
+
[types.FrozenDictLike]
|
|
26
|
+
Data = "frozendict"
|
|
27
|
+
dirData = []
|
|
28
|
+
isabstract = true
|
|
29
|
+
|
|
30
|
+
[types.FrozenDictLike.parents]
|
|
31
|
+
"datahold.DictLike" = true
|
|
32
|
+
"datahold.FrozenMapping" = true
|
|
33
|
+
|
|
34
|
+
[types.FrozenListLike]
|
|
35
|
+
Data = "tuple"
|
|
36
|
+
dirData = []
|
|
37
|
+
isabstract = true
|
|
38
|
+
|
|
39
|
+
[types.FrozenListLike.parents]
|
|
40
|
+
|
|
41
|
+
[types.FrozenMapping]
|
|
42
|
+
dirData = []
|
|
43
|
+
|
|
44
|
+
[types.FrozenMapping.parents]
|
|
45
|
+
"collections.abc.Hashable" = true
|
|
46
|
+
"datahold.Mapping" = true
|
|
47
|
+
|
|
48
|
+
[types.FrozenSetLike]
|
|
49
|
+
Data = "frozenset"
|
|
50
|
+
dirData = []
|
|
51
|
+
isabstract = true
|
|
52
|
+
|
|
53
|
+
[types.FrozenSetLike.parents]
|
|
54
|
+
|
|
55
|
+
[types.ListLike]
|
|
56
|
+
dirData = []
|
|
57
|
+
|
|
58
|
+
[types.ListLike.parents]
|
|
59
|
+
"collections.abc.Hashable" = false
|
|
60
|
+
"collections.abc.Sequence" = true
|
|
61
|
+
|
|
62
|
+
[types.Mapping]
|
|
63
|
+
dirData = []
|
|
64
|
+
|
|
65
|
+
[types.Mapping.parents]
|
|
66
|
+
"collections.abc.Hashable" = false
|
|
67
|
+
"datahold.Collection" = true
|
|
68
|
+
|
|
69
|
+
[types.MutableDictLike]
|
|
70
|
+
Data = "frozendict"
|
|
71
|
+
dirData = []
|
|
72
|
+
isabstract = true
|
|
73
|
+
n_type_params = 2
|
|
74
|
+
|
|
75
|
+
[types.MutableDictLike.constructor.empty]
|
|
76
|
+
valid = false
|
|
77
|
+
|
|
78
|
+
[types.MutableDictLike.parents]
|
|
79
|
+
"collections.abc.MutableMapping" = true
|
|
80
|
+
"datahold.DictLike" = true
|
|
81
|
+
"datahold.Mapping" = true
|
|
82
|
+
|
|
83
|
+
[types.MutableListLike]
|
|
84
|
+
Data = "tuple"
|
|
85
|
+
dirData = []
|
|
86
|
+
isabstract = true
|
|
87
|
+
n_type_params = 1
|
|
88
|
+
|
|
89
|
+
[types.MutableListLike.constructor.empty]
|
|
90
|
+
valid = false
|
|
91
|
+
|
|
92
|
+
[types.MutableListLike.parents]
|
|
93
|
+
"collections.abc.MutableSequence" = true
|
|
94
|
+
"collections.abc.Sequence" = true
|
|
95
|
+
"datahold.ListLike" = true
|
|
96
|
+
|
|
97
|
+
[types.MutableSetLike]
|
|
98
|
+
Data = "frozenset"
|
|
99
|
+
dirData = []
|
|
100
|
+
isabstract = true
|
|
101
|
+
n_type_params = 1
|
|
102
|
+
|
|
103
|
+
[types.MutableSetLike.constructor.empty]
|
|
104
|
+
valid = false
|
|
105
|
+
|
|
106
|
+
[types.MutableSetLike.parents]
|
|
107
|
+
"collections.abc.MutableSet" = true
|
|
108
|
+
"collections.abc.Set" = true
|
|
109
|
+
"datahold.SetLike" = true
|
|
110
|
+
|
|
111
|
+
[types.Sequence]
|
|
112
|
+
dirData = [
|
|
113
|
+
"__contains__",
|
|
114
|
+
"__getitem__",
|
|
115
|
+
"__iter__",
|
|
116
|
+
"__len__",
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
[types.Sequence.parents]
|
|
120
|
+
"collections.abc.Hashable" = true
|
|
121
|
+
"datahold.Collection" = true
|
|
122
|
+
|
|
123
|
+
[types.Set]
|
|
124
|
+
dirData = [
|
|
125
|
+
"__contains__",
|
|
126
|
+
"__iter__",
|
|
127
|
+
"__len__",
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
[types.Set.parents]
|
|
131
|
+
"collections.abc.Hashable" = false
|
|
132
|
+
"datahold.Collection" = true
|
|
133
|
+
|
|
134
|
+
[types.SetLike]
|
|
135
|
+
dirData = []
|
|
136
|
+
|
|
137
|
+
[types.SetLike.parents]
|
|
138
|
+
"collections.abc.Hashable" = false
|
|
139
|
+
"collections.abc.Set" = true
|
|
140
|
+
"datahold.Set" = true
|
|
141
|
+
|
|
142
|
+
[varia]
|
|
143
|
+
HOLD_TYPES = [
|
|
144
|
+
"BaseHoldObject",
|
|
145
|
+
]
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
[test_object]
|
|
2
|
-
METHODS = [
|
|
3
|
-
"__format__",
|
|
4
|
-
"__str__",
|
|
5
|
-
]
|
|
6
|
-
|
|
7
|
-
[types.BaseDataAbstractSet]
|
|
8
|
-
dirData = [
|
|
9
|
-
"__contains__",
|
|
10
|
-
"__iter__",
|
|
11
|
-
"__len__",
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
[types.BaseDataAbstractSet.parents]
|
|
15
|
-
BaseDataCollection = true
|
|
16
|
-
Hashable = false
|
|
17
|
-
|
|
18
|
-
[types.BaseDataCollection]
|
|
19
|
-
dirData = [
|
|
20
|
-
"__contains__",
|
|
21
|
-
"__iter__",
|
|
22
|
-
"__len__",
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
[types.BaseDataCollection.parents]
|
|
26
|
-
Collection = true
|
|
27
|
-
Hashable = true
|
|
28
|
-
|
|
29
|
-
[types.BaseDataDict]
|
|
30
|
-
dirData = []
|
|
31
|
-
|
|
32
|
-
[types.BaseDataDict.parents]
|
|
33
|
-
Hashable = false
|
|
34
|
-
Mapping = true
|
|
35
|
-
|
|
36
|
-
[types.BaseDataList]
|
|
37
|
-
dirData = []
|
|
38
|
-
|
|
39
|
-
[types.BaseDataList.parents]
|
|
40
|
-
Hashable = false
|
|
41
|
-
Sequence = true
|
|
42
|
-
|
|
43
|
-
[types.BaseDataMapping]
|
|
44
|
-
dirData = []
|
|
45
|
-
|
|
46
|
-
[types.BaseDataMapping.parents]
|
|
47
|
-
BaseDataCollection = true
|
|
48
|
-
Hashable = false
|
|
49
|
-
|
|
50
|
-
[types.BaseDataSequence]
|
|
51
|
-
dirData = [
|
|
52
|
-
"__contains__",
|
|
53
|
-
"__getitem__",
|
|
54
|
-
"__iter__",
|
|
55
|
-
"__len__",
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
[types.BaseDataSequence.parents]
|
|
59
|
-
BaseDataCollection = true
|
|
60
|
-
Hashable = true
|
|
61
|
-
|
|
62
|
-
[types.BaseDataSet]
|
|
63
|
-
dirData = []
|
|
64
|
-
|
|
65
|
-
[types.BaseDataSet.parents]
|
|
66
|
-
BaseDataAbstractSet = true
|
|
67
|
-
Hashable = false
|
|
68
|
-
Set = true
|
|
69
|
-
|
|
70
|
-
[types.DataDict]
|
|
71
|
-
Data = "frozendict"
|
|
72
|
-
dirData = []
|
|
73
|
-
isabstract = true
|
|
74
|
-
n_type_params = 2
|
|
75
|
-
|
|
76
|
-
[types.DataDict.constructor.empty]
|
|
77
|
-
valid = false
|
|
78
|
-
|
|
79
|
-
[types.DataDict.parents]
|
|
80
|
-
BaseDataDict = true
|
|
81
|
-
BaseDataMapping = true
|
|
82
|
-
MutableMapping = true
|
|
83
|
-
|
|
84
|
-
[types.DataList]
|
|
85
|
-
Data = "tuple"
|
|
86
|
-
dirData = []
|
|
87
|
-
isabstract = true
|
|
88
|
-
n_type_params = 1
|
|
89
|
-
|
|
90
|
-
[types.DataList.constructor.empty]
|
|
91
|
-
valid = false
|
|
92
|
-
|
|
93
|
-
[types.DataList.parents]
|
|
94
|
-
BaseDataList = true
|
|
95
|
-
MutableSequence = true
|
|
96
|
-
Sequence = true
|
|
97
|
-
|
|
98
|
-
[types.DataSet]
|
|
99
|
-
Data = "frozenset"
|
|
100
|
-
dirData = []
|
|
101
|
-
isabstract = true
|
|
102
|
-
n_type_params = 1
|
|
103
|
-
|
|
104
|
-
[types.DataSet.constructor.empty]
|
|
105
|
-
valid = false
|
|
106
|
-
|
|
107
|
-
[types.DataSet.parents]
|
|
108
|
-
BaseDataSet = true
|
|
109
|
-
MutableSet = true
|
|
110
|
-
Set = true
|
|
111
|
-
|
|
112
|
-
[types.FrozenDataDict]
|
|
113
|
-
Data = "frozendict"
|
|
114
|
-
dirData = []
|
|
115
|
-
isabstract = true
|
|
116
|
-
|
|
117
|
-
[types.FrozenDataDict.parents]
|
|
118
|
-
|
|
119
|
-
[types.FrozenDataList]
|
|
120
|
-
Data = "tuple"
|
|
121
|
-
dirData = []
|
|
122
|
-
isabstract = true
|
|
123
|
-
|
|
124
|
-
[types.FrozenDataList.parents]
|
|
125
|
-
|
|
126
|
-
[types.FrozenDataSet]
|
|
127
|
-
Data = "frozenset"
|
|
128
|
-
dirData = []
|
|
129
|
-
isabstract = true
|
|
130
|
-
|
|
131
|
-
[types.FrozenDataSet.parents]
|
|
132
|
-
|
|
133
|
-
[varia]
|
|
134
|
-
HOLD_TYPES = [
|
|
135
|
-
"BaseHoldObject",
|
|
136
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|