diff --git a/plot.py b/plot.py index 78bc618..9b99df2 100644 --- a/plot.py +++ b/plot.py @@ -1,5 +1,6 @@ import json from pathlib import Path +from typing import Any import matplotlib.pyplot as plt import numpy as np @@ -32,7 +33,7 @@ def plot(fn: str): plt.ylabel('concurrency (1)') with open(fn) as file: - jsonified: dict[str] = json.load(file) + jsonified: dict[str, Any] = json.load(file) title = fn if (params := jsonified.pop('params', None)) is not None: @@ -52,6 +53,7 @@ def plot(fn: str): logplot(plt.scatter, 'ActiveBinaryTree:add:exit', c='gold', zorder=99, s=.5) plt.legend() + plt.savefig(f'{fn}.png') plt.show() plt.clf() diff --git a/rainbowadn/atomic/atomic.py b/rainbowadn/atomic/atomic.py index b269937..ec9dc60 100644 --- a/rainbowadn/atomic/atomic.py +++ b/rainbowadn/atomic/atomic.py @@ -5,7 +5,7 @@ from rainbowadn.core import * __all__ = ('Atomic',) -AtomicMentioned = TypeVar('AtomicMentioned') +AtomicMentioned = TypeVar('AtomicMentioned', bound='Atomic') class Atomic(StaticMentionable, abc.ABC): diff --git a/rainbowadn/collection/collectioninterface.py b/rainbowadn/collection/collectioninterface.py index 95599b3..f1d3950 100644 --- a/rainbowadn/collection/collectioninterface.py +++ b/rainbowadn/collection/collectioninterface.py @@ -1,10 +1,11 @@ from typing import Generic, TypeVar +from rainbowadn.core import * from rainbowadn.nullability import * __all__ = ('CollectionInterface',) -CollectionType = TypeVar('CollectionType') +CollectionType = TypeVar('CollectionType', bound=Mentionable, covariant=True) class CollectionInterface( diff --git a/rainbowadn/collection/comparison/__init__.py b/rainbowadn/collection/comparison/__init__.py index a9df17b..2ad009b 100644 --- a/rainbowadn/collection/comparison/__init__.py +++ b/rainbowadn/collection/comparison/__init__.py @@ -5,7 +5,10 @@ __all__ = ( 'PlainComparator', ) -from .comparator import Comparator, Comparison, Duplicate, Equal, Fail, Left, Replace, Right +from .comparator import ( + Comparator, Comparison, Duplicate, Equal, Fail, Left, + Replace, Right +) from .hashcomparator import HashComparator from .keyedcomparator import KeyedComparator from .plaincomparator import PlainComparator diff --git a/rainbowadn/collection/comparison/comparator.py b/rainbowadn/collection/comparison/comparator.py index 72f115a..946d426 100644 --- a/rainbowadn/collection/comparison/comparator.py +++ b/rainbowadn/collection/comparison/comparator.py @@ -36,7 +36,7 @@ class Duplicate(Equal): pass -KeyType = TypeVar('KeyType') +KeyType = TypeVar('KeyType', bound=Mentionable, contravariant=True) class Comparator(Generic[KeyType]): diff --git a/rainbowadn/collection/comparison/hashcomparator.py b/rainbowadn/collection/comparison/hashcomparator.py index 5a87899..bccc434 100644 --- a/rainbowadn/collection/comparison/hashcomparator.py +++ b/rainbowadn/collection/comparison/hashcomparator.py @@ -1,12 +1,13 @@ from typing import Generic, TypeVar from rainbowadn.core import * + from .comparator import * from .protocolcomparator import * __all__ = ('HashComparator',) -KeyType = TypeVar('KeyType') +KeyType = TypeVar('KeyType', bound=Mentionable, contravariant=True) class HashComparator(ProtocolComparator[KeyType], Generic[KeyType]): diff --git a/rainbowadn/collection/comparison/keyedcomparator.py b/rainbowadn/collection/comparison/keyedcomparator.py index 03bfcf6..b8bf781 100644 --- a/rainbowadn/collection/comparison/keyedcomparator.py +++ b/rainbowadn/collection/comparison/keyedcomparator.py @@ -2,11 +2,12 @@ from typing import Generic, TypeVar from rainbowadn.collection.keyed import * from rainbowadn.core import * + from .comparator import * __all__ = ('KeyedComparator',) -ComparatorKeyType = TypeVar('ComparatorKeyType') +ComparatorKeyType = TypeVar('ComparatorKeyType', bound=Mentionable, contravariant=True) class KeyedComparator( diff --git a/rainbowadn/collection/comparison/plaincomparator.py b/rainbowadn/collection/comparison/plaincomparator.py index 981dc68..1bffaa9 100644 --- a/rainbowadn/collection/comparison/plaincomparator.py +++ b/rainbowadn/collection/comparison/plaincomparator.py @@ -1,5 +1,6 @@ from rainbowadn.atomic import * from rainbowadn.core import * + from .comparator import * from .protocolcomparator import * diff --git a/rainbowadn/collection/comparison/protocolcomparator.py b/rainbowadn/collection/comparison/protocolcomparator.py index f3ec3d2..b2e18ea 100644 --- a/rainbowadn/collection/comparison/protocolcomparator.py +++ b/rainbowadn/collection/comparison/protocolcomparator.py @@ -1,11 +1,13 @@ import abc from typing import Generic, TypeVar +from rainbowadn.core import * + from .comparator import * __all__ = ('ProtocolComparator',) -KeyType = TypeVar('KeyType') +KeyType = TypeVar('KeyType', bound=Mentionable, contravariant=True) class ProtocolComparator(Comparator[KeyType], abc.ABC, Generic[KeyType]): diff --git a/rainbowadn/collection/keyed.py b/rainbowadn/collection/keyed.py index 9e9d966..94c35a6 100644 --- a/rainbowadn/collection/keyed.py +++ b/rainbowadn/collection/keyed.py @@ -5,7 +5,7 @@ from rainbowadn.core import * __all__ = ('Keyed',) -KKeyType = TypeVar('KKeyType') +KKeyType = TypeVar('KKeyType', bound=Mentionable, covariant=True) class Keyed(RecursiveMentionable, Generic[KKeyType], abc.ABC): diff --git a/rainbowadn/collection/keymetadata.py b/rainbowadn/collection/keymetadata.py index 0ba7ce7..3d8a696 100644 --- a/rainbowadn/collection/keymetadata.py +++ b/rainbowadn/collection/keymetadata.py @@ -1,12 +1,13 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.core import * + from .keyed import * __all__ = ('KeyMetadata', 'KeyMetadataFactory',) -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable, covariant=True) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable, covariant=True) class KeyMetadata(Keyed[ActiveKeyType], Generic[ActiveKeyType, MetaDataType]): diff --git a/rainbowadn/collection/keyvalue.py b/rainbowadn/collection/keyvalue.py index 89822f1..f6b3be1 100644 --- a/rainbowadn/collection/keyvalue.py +++ b/rainbowadn/collection/keyvalue.py @@ -2,12 +2,13 @@ from typing import Generic, TypeVar from rainbowadn.core import * from rainbowadn.inlining import * + from .keyed import * __all__ = ('KeyValue',) -KVKeyType = TypeVar('KVKeyType') -KVValueType = TypeVar('KVValueType') +KVKeyType = TypeVar('KVKeyType', bound=Mentionable) +KVValueType = TypeVar('KVValueType', bound=Mentionable) class KeyValue(Keyed[KVKeyType], IAuto, Generic[KVKeyType, KVValueType]): @@ -36,6 +37,7 @@ class KeyValue(Keyed[KVKeyType], IAuto, Generic[KVKeyType, KVValueType]): def f( cls, f0: RainbowFactory[KVKeyType], f1: RainbowFactory[KVValueType] ) -> RainbowFactory['KeyValue[KVKeyType, KVValueType]']: + assert issubclass(cls, KeyValue) assert isinstance(f0, RainbowFactory) assert isinstance(f1, RainbowFactory) return cls.auto_f(f0, f1) diff --git a/rainbowadn/collection/linear/__init__.py b/rainbowadn/collection/linear/__init__.py index ab06c32..cca475f 100644 --- a/rainbowadn/collection/linear/__init__.py +++ b/rainbowadn/collection/linear/__init__.py @@ -3,5 +3,5 @@ __all__ = ( 'TLRoot', 'TLRootFactory', 'TLRParametres', ) -from .array import Array, ArrayFactory -from .treelist import TLRParametres, TLRoot, TLRootFactory +from ._array import Array, ArrayFactory +from .treelist import TLRoot, TLRootFactory, TLRParametres diff --git a/rainbowadn/collection/linear/array.py b/rainbowadn/collection/linear/_array.py similarity index 96% rename from rainbowadn/collection/linear/array.py rename to rainbowadn/collection/linear/_array.py index 74b3b4e..fc17670 100644 --- a/rainbowadn/collection/linear/array.py +++ b/rainbowadn/collection/linear/_array.py @@ -4,7 +4,7 @@ from rainbowadn.core import * __all__ = ('Array', 'ArrayFactory',) -ElementType = TypeVar('ElementType') +ElementType = TypeVar('ElementType', bound=Mentionable, covariant=True) class Array(RecursiveMentionable, Generic[ElementType]): diff --git a/rainbowadn/collection/linear/treelist/tlnode.py b/rainbowadn/collection/linear/treelist/tlnode.py index 33e77af..4c1bf18 100644 --- a/rainbowadn/collection/linear/treelist/tlnode.py +++ b/rainbowadn/collection/linear/treelist/tlnode.py @@ -1,11 +1,12 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.core import * + from .tlparametres import * __all__ = ('TLNode', 'TLNodeFactory',) -ElementType = TypeVar('ElementType') +ElementType = TypeVar('ElementType', bound=Mentionable) class TLNode(RecursiveMentionable, Generic[ElementType]): @@ -101,9 +102,10 @@ class TLNode(RecursiveMentionable, Generic[ElementType]): return await self.node_no_resolved(self.nodes - 1) async def add(self, element: HashPoint[ElementType]) -> 'TLNode[ElementType]': + assert isinstance(self, TLNode) assert isinstance(element, HashPoint) if self.parametres.full: - self_hp = HashPoint.of(self) + self_hp: HashPoint[TLNode[ElementType]] = HashPoint.of(self) assert isinstance(self_hp, HashPoint) unit = self.unit(element) assert isinstance(unit, TLNode) @@ -112,7 +114,7 @@ class TLNode(RecursiveMentionable, Generic[ElementType]): return TLNode( bytes(self_hp) + bytes(unit_hp), self.parametres.superparams(), - (LocalMetaOrigin(self_hp.origin), LocalMetaOrigin(unit_hp.origin)), + (LocalMetaOrigin(self_hp.origin), LocalMetaOrigin(unit_hp.origin),), (), ) elif self.parametres.leaf: diff --git a/rainbowadn/collection/linear/treelist/tlparametres.py b/rainbowadn/collection/linear/treelist/tlparametres.py index 885c634..bdfb42c 100644 --- a/rainbowadn/collection/linear/treelist/tlparametres.py +++ b/rainbowadn/collection/linear/treelist/tlparametres.py @@ -1,10 +1,12 @@ from typing import Generic, TypeVar +from rainbowadn.core import * + from .tlrparametres import * __all__ = ('TLParametres',) -ElementType = TypeVar('ElementType') +ElementType = TypeVar('ElementType', bound=Mentionable) class TLParametres( diff --git a/rainbowadn/collection/linear/treelist/tlroot.py b/rainbowadn/collection/linear/treelist/tlroot.py index ad46dac..d261a8f 100644 --- a/rainbowadn/collection/linear/treelist/tlroot.py +++ b/rainbowadn/collection/linear/treelist/tlroot.py @@ -2,13 +2,14 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.atomic import * from rainbowadn.core import * + from .tlnode import * from .tlparametres import * from .tlrparametres import * __all__ = ('TLRoot', 'TLRootFactory',) -ElementType = TypeVar('ElementType') +ElementType = TypeVar('ElementType', bound=Mentionable) class TLRoot(RecursiveMentionable, Generic[ElementType]): diff --git a/rainbowadn/collection/linear/treelist/tlrparametres.py b/rainbowadn/collection/linear/treelist/tlrparametres.py index 7a2a713..8e9ea83 100644 --- a/rainbowadn/collection/linear/treelist/tlrparametres.py +++ b/rainbowadn/collection/linear/treelist/tlrparametres.py @@ -4,7 +4,7 @@ from rainbowadn.core import * __all__ = ('TLRParametres',) -ElementType = TypeVar('ElementType') +ElementType = TypeVar('ElementType', bound=Mentionable) class TLRParametres( diff --git a/rainbowadn/collection/trees/binary/actions/__init__.py b/rainbowadn/collection/trees/binary/actions/__init__.py index b2d5461..a869715 100644 --- a/rainbowadn/collection/trees/binary/actions/__init__.py +++ b/rainbowadn/collection/trees/binary/actions/__init__.py @@ -7,5 +7,8 @@ __all__ = ( from .binaryaction import BinaryAction from .compareaction import CompareAction -from .stdactions import AddAction, ContainsAction, MergeAction, RemoveAction, SplitAction, UnionAction +from .stdactions import ( + AddAction, ContainsAction, MergeAction, RemoveAction, + SplitAction, UnionAction +) from .symmetric import InnerOuter, OuterInner, Symmetric diff --git a/rainbowadn/collection/trees/binary/actions/binaryaction.py b/rainbowadn/collection/trees/binary/actions/binaryaction.py index 7846057..8fe3f2e 100644 --- a/rainbowadn/collection/trees/binary/actions/binaryaction.py +++ b/rainbowadn/collection/trees/binary/actions/binaryaction.py @@ -1,12 +1,13 @@ from typing import Generic, TypeVar from rainbowadn.collection.trees.binary.core import * +from rainbowadn.core import * __all__ = ('BinaryAction',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) ActionType = TypeVar('ActionType') diff --git a/rainbowadn/collection/trees/binary/actions/compareaction.py b/rainbowadn/collection/trees/binary/actions/compareaction.py index a8856cd..2bff00a 100644 --- a/rainbowadn/collection/trees/binary/actions/compareaction.py +++ b/rainbowadn/collection/trees/binary/actions/compareaction.py @@ -4,13 +4,14 @@ from typing import Generic, TypeVar from rainbowadn.collection.comparison import * from rainbowadn.collection.trees.binary.core import * from rainbowadn.core import * + from .binaryaction import * __all__ = ('CompareAction',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) ActionType = TypeVar('ActionType') diff --git a/rainbowadn/collection/trees/binary/actions/stdactions.py b/rainbowadn/collection/trees/binary/actions/stdactions.py index c25ee90..5c9c372 100644 --- a/rainbowadn/collection/trees/binary/actions/stdactions.py +++ b/rainbowadn/collection/trees/binary/actions/stdactions.py @@ -3,14 +3,15 @@ from typing import Generic, TypeVar from rainbowadn.collection.comparison import * from rainbowadn.collection.trees.binary.core import * from rainbowadn.core import * + from .binaryaction import * from .compareaction import * __all__ = ('AddAction', 'RemoveAction', 'ContainsAction', 'SplitAction', 'UnionAction', 'MergeAction',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class AddAction( diff --git a/rainbowadn/collection/trees/binary/actions/symmetric.py b/rainbowadn/collection/trees/binary/actions/symmetric.py index 2b69c44..fba4ba8 100644 --- a/rainbowadn/collection/trees/binary/actions/symmetric.py +++ b/rainbowadn/collection/trees/binary/actions/symmetric.py @@ -6,8 +6,8 @@ from rainbowadn.core import * __all__ = ('Symmetric', 'InnerOuter', 'OuterInner',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class Symmetric( @@ -55,7 +55,10 @@ class Symmetric( return BinaryProtocolized(self.protocol, self.outer(split)) -class InnerOuter(Symmetric): +class InnerOuter( + Symmetric[ActiveKeyType, MetaDataType, TreeType], + Generic[ActiveKeyType, MetaDataType, TreeType] +): def inner( self, split: BinarySplit[ActiveKeyType, MetaDataType, TreeType] @@ -80,7 +83,10 @@ class InnerOuter(Symmetric): return await self.protocol.tree(inner, outer, key) -class OuterInner(Symmetric): +class OuterInner( + Symmetric[ActiveKeyType, MetaDataType, TreeType], + Generic[ActiveKeyType, MetaDataType, TreeType] +): def inner( self, split: BinarySplit[ActiveKeyType, MetaDataType, TreeType] diff --git a/rainbowadn/collection/trees/binary/activebinarytree.py b/rainbowadn/collection/trees/binary/activebinarytree.py index 1580ecb..1c5acc9 100644 --- a/rainbowadn/collection/trees/binary/activebinarytree.py +++ b/rainbowadn/collection/trees/binary/activebinarytree.py @@ -4,14 +4,15 @@ from rainbowadn.collection.collectioninterface import * from rainbowadn.collection.keymetadata import * from rainbowadn.core import * from rainbowadn.nullability import * + from .actions import * from .binarytree import * from .core import * __all__ = ('ActiveBinaryTree',) -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class ActiveBinaryTree( diff --git a/rainbowadn/collection/trees/binary/avl.py b/rainbowadn/collection/trees/binary/avl.py index 9fe53d4..761c217 100644 --- a/rainbowadn/collection/trees/binary/avl.py +++ b/rainbowadn/collection/trees/binary/avl.py @@ -3,12 +3,13 @@ from typing import Generic, Optional, TypeVar from rainbowadn.atomic import * from rainbowadn.collection.comparison import * from rainbowadn.core import * + from .actions import * from .core import * __all__ = ('AVL',) -ActiveKeyType = TypeVar('ActiveKeyType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) TreeType = TypeVar('TreeType') @@ -138,11 +139,11 @@ class BalanceAction( delta = height_l - height_r assert isinstance(delta, int) if delta < -1: - splitr: BinarySplit[ActiveKeyType, Integer, TreeType] + splitr: BinarySplit[ActiveKeyType, Integer, TreeType] | None assert isinstance(splitr, BinarySplit) return await self.on_symmetric(InnerOuter(case.protocol), case.split.treel, case.split.key, splitr) elif delta > 1: - splitl: BinarySplit[ActiveKeyType, Integer, TreeType] + splitl: BinarySplit[ActiveKeyType, Integer, TreeType] | None assert isinstance(splitl, BinarySplit) return await self.on_symmetric(OuterInner(case.protocol), case.split.treer, case.split.key, splitl) else: @@ -166,7 +167,7 @@ class BalanceAction( assert isinstance(height_oi, int) assert isinstance(height_oo, int) if height_oi > height_oo: - splitoi: BinarySplit[ActiveKeyType, Integer, TreeType] + splitoi: BinarySplit[ActiveKeyType, Integer, TreeType] | None assert isinstance(splitoi, BinarySplit) inner, outer = await gather( symmetry.tree(treei, symmetry.inner(splitoi), key), diff --git a/rainbowadn/collection/trees/binary/binarytree.py b/rainbowadn/collection/trees/binary/binarytree.py index ac063b0..66bbf07 100644 --- a/rainbowadn/collection/trees/binary/binarytree.py +++ b/rainbowadn/collection/trees/binary/binarytree.py @@ -5,7 +5,7 @@ from rainbowadn.nullability import * __all__ = ('BinaryTree', 'BinaryTreeFactory',) -TreeKeyType = TypeVar('TreeKeyType') +TreeKeyType = TypeVar('TreeKeyType', bound=Mentionable) class BinaryTree(RecursiveMentionable, Generic[TreeKeyType]): @@ -28,7 +28,7 @@ class BinaryTree(RecursiveMentionable, Generic[TreeKeyType]): assert isinstance(key, Mentionable) self.treel = treel self.treer = treer - self.key = key + self.key: TreeKeyType = key def points(self) -> Iterable[HashPoint]: return [*self.treel.points(), *self.treer.points(), *RecursiveMentionable.points_of(self.key)] diff --git a/rainbowadn/collection/trees/binary/core/balancedcreation.py b/rainbowadn/collection/trees/binary/core/balancedcreation.py index 342a7df..c42b1ce 100644 --- a/rainbowadn/collection/trees/binary/core/balancedcreation.py +++ b/rainbowadn/collection/trees/binary/core/balancedcreation.py @@ -2,6 +2,7 @@ import abc from typing import Generic, TypeVar from rainbowadn.core import * + from .binarybalancing import * from .binarycreation import * from .binaryprotocolized import * @@ -9,8 +10,8 @@ from .binaryprotocolized import * __all__ = ('BalancedCreation',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class BalancedCreation( diff --git a/rainbowadn/collection/trees/binary/core/binarybalancing.py b/rainbowadn/collection/trees/binary/core/binarybalancing.py index f8a90d4..2047c8e 100644 --- a/rainbowadn/collection/trees/binary/core/binarybalancing.py +++ b/rainbowadn/collection/trees/binary/core/binarybalancing.py @@ -3,14 +3,15 @@ from typing import Generic, TypeVar from rainbowadn.collection.comparison import * from rainbowadn.core import * + from .binarymetadata import * from .binaryprotocolized import * __all__ = ('BinaryBalancing',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class BinaryBalancing( diff --git a/rainbowadn/collection/trees/binary/core/binarycreation.py b/rainbowadn/collection/trees/binary/core/binarycreation.py index a9cd1e3..c5856b9 100644 --- a/rainbowadn/collection/trees/binary/core/binarycreation.py +++ b/rainbowadn/collection/trees/binary/core/binarycreation.py @@ -2,13 +2,14 @@ from typing import Generic, Optional, TypeVar from rainbowadn.collection.comparison import * from rainbowadn.core import * + from .binarysplit import * __all__ = ('BinaryCreation',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class BinaryCreation(Generic[ActiveKeyType, MetaDataType, TreeType]): diff --git a/rainbowadn/collection/trees/binary/core/binarymetadata.py b/rainbowadn/collection/trees/binary/core/binarymetadata.py index 18aa86f..40854a6 100644 --- a/rainbowadn/collection/trees/binary/core/binarymetadata.py +++ b/rainbowadn/collection/trees/binary/core/binarymetadata.py @@ -1,13 +1,14 @@ from typing import Generic, TypeVar from rainbowadn.core import * + from .binarycreation import * __all__ = ('BinaryMetadata',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class BinaryMetadata(Generic[ActiveKeyType, MetaDataType, TreeType]): diff --git a/rainbowadn/collection/trees/binary/core/binaryprotocolized.py b/rainbowadn/collection/trees/binary/core/binaryprotocolized.py index 233b5b2..6ae9cfd 100644 --- a/rainbowadn/collection/trees/binary/core/binaryprotocolized.py +++ b/rainbowadn/collection/trees/binary/core/binaryprotocolized.py @@ -1,13 +1,15 @@ from typing import Generic, Optional, TypeVar +from rainbowadn.core import * + from .binarycreation import * from .binarysplit import * __all__ = ('BinaryProtocolized',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class BinaryProtocolized( diff --git a/rainbowadn/collection/trees/binary/core/binarysplit.py b/rainbowadn/collection/trees/binary/core/binarysplit.py index 1a9c12e..46dbdc3 100644 --- a/rainbowadn/collection/trees/binary/core/binarysplit.py +++ b/rainbowadn/collection/trees/binary/core/binarysplit.py @@ -5,8 +5,8 @@ from rainbowadn.core import * __all__ = ('BinarySplit',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class BinarySplit( diff --git a/rainbowadn/collection/trees/binary/core/protocolizedbinarysplit.py b/rainbowadn/collection/trees/binary/core/protocolizedbinarysplit.py index 86cab57..8b1ea34 100644 --- a/rainbowadn/collection/trees/binary/core/protocolizedbinarysplit.py +++ b/rainbowadn/collection/trees/binary/core/protocolizedbinarysplit.py @@ -1,6 +1,7 @@ from typing import Generic, Optional, TypeVar from rainbowadn.core import * + from .binarycreation import * from .binaryprotocolized import * from .binarysplit import * @@ -8,8 +9,8 @@ from .binarysplit import * __all__ = ('ProtocolizedBinarySplit',) TreeType = TypeVar('TreeType') -ActiveKeyType = TypeVar('ActiveKeyType') -MetaDataType = TypeVar('MetaDataType') +ActiveKeyType = TypeVar('ActiveKeyType', bound=Mentionable) +MetaDataType = TypeVar('MetaDataType', bound=Mentionable) class ProtocolizedBinarySplit( diff --git a/rainbowadn/core/__init__.py b/rainbowadn/core/__init__.py index cafe8ff..0008eb2 100644 --- a/rainbowadn/core/__init__.py +++ b/rainbowadn/core/__init__.py @@ -17,11 +17,20 @@ __all__ = ( 'StaticMentionable', 'StaticFactory', ) -from .asserts import assert_eq, assert_false, assert_none, assert_none_strict, assert_true, assert_trues +from .asserts import ( + assert_eq, assert_false, assert_none, assert_none_strict, + assert_true, assert_trues +) from .extendableresolver import ExtendableResolver -from .gather import aidentity, alist, asum, gather, set_gather_asyncio, set_gather_linear +from .gather import ( + aidentity, alist, asum, gather, set_gather_asyncio, + set_gather_linear +) from .hashpoint import HashPoint -from .hashpointformat import disable_newline, enable_newline, hash_point_format, tabulate +from .hashpointformat import ( + disable_newline, enable_newline, + hash_point_format, tabulate +) from .hashresolver import HashResolver from .localmetaorigin import LocalMetaOrigin from .localorigin import LocalOrigin diff --git a/rainbowadn/core/asserts.py b/rainbowadn/core/asserts.py index 53882a0..21f9fa3 100644 --- a/rainbowadn/core/asserts.py +++ b/rainbowadn/core/asserts.py @@ -1,4 +1,4 @@ -from typing import Iterable, Optional, TypeVar +from typing import Any, Iterable, Optional, TypeVar __all__ = ('assert_true', 'assert_trues', 'assert_false', 'assert_none', 'assert_none_strict', 'assert_eq',) @@ -22,7 +22,7 @@ def assert_false(value: bool) -> bool: T = TypeVar('T') -def assert_none(value: Optional[T]) -> bool: +def assert_none(value: Optional[Any]) -> bool: assert value is None return True diff --git a/rainbowadn/core/extendableresolver.py b/rainbowadn/core/extendableresolver.py index f3ca2fe..5b07571 100644 --- a/rainbowadn/core/extendableresolver.py +++ b/rainbowadn/core/extendableresolver.py @@ -8,11 +8,11 @@ from .resolvermetaorigin import * __all__ = ('ExtendableResolver',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable) class ExtendableResolver(HashResolver, abc.ABC): - async def extend(self, hash_point: HashPoint[Mentioned]) -> 'ExtendableResolver': + async def extend(self, hash_point: HashPoint[Mentionable]) -> 'ExtendableResolver': raise NotImplementedError async def migrate(self, hash_point: HashPoint[Mentioned]) -> HashPoint[Mentioned]: diff --git a/rainbowadn/core/gather.py b/rainbowadn/core/gather.py index 30467db..b958752 100644 --- a/rainbowadn/core/gather.py +++ b/rainbowadn/core/gather.py @@ -3,11 +3,11 @@ from typing import Any, AsyncIterable, Awaitable, Coroutine, TypeVar, overload __all__ = ('gather', 'asum', 'alist', 'set_gather_asyncio', 'set_gather_linear', 'aidentity',) -_gather = asyncio.gather +_gather: Any = asyncio.gather async def _local_gather(*args): - return [await arg for arg in args] + return tuple([await arg for arg in args]) def set_gather_asyncio(): @@ -29,35 +29,39 @@ T4 = TypeVar('T4') @overload def gather( - a0: Coroutine[Any, Any, T0], - a1: Coroutine[Any, Any, T1], + a0: Coroutine[Any, Any, T0], + a1: Coroutine[Any, Any, T1], + / ) -> Awaitable[tuple[T0, T1]]: ... @overload def gather( - a0: Coroutine[Any, Any, T0], - a1: Coroutine[Any, Any, T1], - a2: Coroutine[Any, Any, T2], + a0: Coroutine[Any, Any, T0], + a1: Coroutine[Any, Any, T1], + a2: Coroutine[Any, Any, T2], + / ) -> Awaitable[tuple[T0, T1, T2]]: ... @overload def gather( - a0: Coroutine[Any, Any, T0], - a1: Coroutine[Any, Any, T1], - a2: Coroutine[Any, Any, T2], - a3: Coroutine[Any, Any, T3], + a0: Coroutine[Any, Any, T0], + a1: Coroutine[Any, Any, T1], + a2: Coroutine[Any, Any, T2], + a3: Coroutine[Any, Any, T3], + / ) -> Awaitable[tuple[T0, T1, T2, T3]]: ... @overload def gather( - a0: Coroutine[Any, Any, T0], - a1: Coroutine[Any, Any, T1], - a2: Coroutine[Any, Any, T2], - a3: Coroutine[Any, Any, T3], - a4: Coroutine[Any, Any, T4], + a0: Coroutine[Any, Any, T0], + a1: Coroutine[Any, Any, T1], + a2: Coroutine[Any, Any, T2], + a3: Coroutine[Any, Any, T3], + a4: Coroutine[Any, Any, T4], + / ) -> Awaitable[tuple[T0, T1, T2, T3, T4]]: ... diff --git a/rainbowadn/core/hashpoint.py b/rainbowadn/core/hashpoint.py index 64b3e6d..31f5e57 100644 --- a/rainbowadn/core/hashpoint.py +++ b/rainbowadn/core/hashpoint.py @@ -9,7 +9,8 @@ from .rainbow_factory import * __all__ = ('HashPoint',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable, covariant=True) +MentionedI = TypeVar('MentionedI', bound=Mentionable) def _hash(source: bytes) -> bytes: @@ -54,7 +55,8 @@ class HashPoint(Generic[Mentioned]): return topology_hash + bytes(mentioned) @classmethod - def of(cls, mentioned: Mentioned) -> 'HashPoint[Mentioned]': + def of(cls, mentioned: MentionedI) -> 'HashPoint[MentionedI]': + assert issubclass(cls, HashPoint) assert isinstance(mentioned, Mentionable) return cls( cls.hash(cls.bytes_of_mentioned(mentioned)), LocalOrigin(mentioned) diff --git a/rainbowadn/core/localmetaorigin.py b/rainbowadn/core/localmetaorigin.py index 309300d..e80041e 100644 --- a/rainbowadn/core/localmetaorigin.py +++ b/rainbowadn/core/localmetaorigin.py @@ -2,13 +2,14 @@ from typing import Generic, TypeVar from .asserts import * from .hashpoint import * +from .mentionable import * from .metaorigin import * from .origin import * from .rainbow_factory import * __all__ = ('LocalMetaOrigin',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable) class LocalMetaOrigin(MetaOrigin[Mentioned], Generic[Mentioned]): diff --git a/rainbowadn/core/metaorigin.py b/rainbowadn/core/metaorigin.py index c127e7b..0c9b08e 100644 --- a/rainbowadn/core/metaorigin.py +++ b/rainbowadn/core/metaorigin.py @@ -2,12 +2,13 @@ from typing import Generic, TypeVar from .asserts import * from .hashpoint import * +from .mentionable import * from .origin import * from .rainbow_factory import * __all__ = ('MetaOrigin',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable, covariant=True) class MetaOrigin(Generic[Mentioned]): diff --git a/rainbowadn/core/origin.py b/rainbowadn/core/origin.py index d6fea8b..7a0ae8c 100644 --- a/rainbowadn/core/origin.py +++ b/rainbowadn/core/origin.py @@ -4,7 +4,7 @@ from .rainbow_factory import * __all__ = ('Origin',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', covariant=True) class Origin(Generic[Mentioned]): diff --git a/rainbowadn/core/rainbow_factory.py b/rainbowadn/core/rainbow_factory.py index 1391212..2b7830a 100644 --- a/rainbowadn/core/rainbow_factory.py +++ b/rainbowadn/core/rainbow_factory.py @@ -4,7 +4,7 @@ from .hashresolver import * __all__ = ('RainbowFactory',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', covariant=True) class RainbowFactory(Generic[Mentioned]): diff --git a/rainbowadn/core/resolvermetaorigin.py b/rainbowadn/core/resolvermetaorigin.py index 7db318f..b663bd9 100644 --- a/rainbowadn/core/resolvermetaorigin.py +++ b/rainbowadn/core/resolvermetaorigin.py @@ -3,6 +3,7 @@ from typing import Generic, TypeVar from .asserts import * from .hashpoint import * from .hashresolver import * +from .mentionable import * from .metaorigin import * from .origin import * from .rainbow_factory import * @@ -10,7 +11,7 @@ from .resolverorigin import * __all__ = ('ResolverMetaOrigin',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable, covariant=True) class ResolverMetaOrigin(MetaOrigin[Mentioned], Generic[Mentioned]): diff --git a/rainbowadn/core/resolverorigin.py b/rainbowadn/core/resolverorigin.py index bf56269..0fd7817 100644 --- a/rainbowadn/core/resolverorigin.py +++ b/rainbowadn/core/resolverorigin.py @@ -9,7 +9,7 @@ from .rainbow_factory import * __all__ = ('ResolverOrigin',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable, covariant=True) class ResolverOrigin(Origin[Mentioned], Generic[Mentioned]): diff --git a/rainbowadn/core/static.py b/rainbowadn/core/static.py index 0f210af..adcf5b1 100644 --- a/rainbowadn/core/static.py +++ b/rainbowadn/core/static.py @@ -7,7 +7,7 @@ from .rainbow_factory import * __all__ = ('StaticMentionable', 'StaticFactory',) -StaticMentioned = TypeVar('StaticMentioned') +StaticMentioned = TypeVar('StaticMentioned', bound='StaticMentionable') class StaticMentionable(Mentionable, abc.ABC): diff --git a/rainbowadn/encryption/encrypted.py b/rainbowadn/encryption/encrypted.py index b5c7c3a..0293305 100644 --- a/rainbowadn/encryption/encrypted.py +++ b/rainbowadn/encryption/encrypted.py @@ -7,7 +7,7 @@ from rainbowadn.core import * __all__ = ('Encrypted', 'EncryptedFactory',) -EncryptedType = TypeVar('EncryptedType') +EncryptedType = TypeVar('EncryptedType', bound=Mentionable) class Encrypted(RecursiveMentionable, Generic[EncryptedType]): diff --git a/rainbowadn/flow/core/_callablemapper.py b/rainbowadn/flow/core/_callablemapper.py index 5dd9701..b989419 100644 --- a/rainbowadn/flow/core/_callablemapper.py +++ b/rainbowadn/flow/core/_callablemapper.py @@ -4,8 +4,8 @@ from ._mapper import Mapper __all__ = ('CallableMapper',) -Element = TypeVar('Element') -Mapped = TypeVar('Mapped') +Element = TypeVar('Element', contravariant=True) +Mapped = TypeVar('Mapped', covariant=True) class CallableMapper( diff --git a/rainbowadn/flow/core/_composition.py b/rainbowadn/flow/core/_composition.py index 305b72e..0fd18f6 100644 --- a/rainbowadn/flow/core/_composition.py +++ b/rainbowadn/flow/core/_composition.py @@ -4,9 +4,9 @@ from ._mapper import * __all__ = ('Composition',) -Element = TypeVar('Element') +Element = TypeVar('Element', contravariant=True) Middle = TypeVar('Middle') -Mapped = TypeVar('Mapped') +Mapped = TypeVar('Mapped', covariant=True) class Composition( diff --git a/rainbowadn/flow/core/_mapper.py b/rainbowadn/flow/core/_mapper.py index fdd72fd..5b0455d 100644 --- a/rainbowadn/flow/core/_mapper.py +++ b/rainbowadn/flow/core/_mapper.py @@ -2,8 +2,8 @@ from typing import Any, Callable, Coroutine, Generic, TypeVar __all__ = ('Mapper',) -Element = TypeVar('Element') -Mapped = TypeVar('Mapped') +Element = TypeVar('Element', contravariant=True) +Mapped = TypeVar('Mapped', covariant=True) class Mapper(Generic[Element, Mapped]): diff --git a/rainbowadn/flow/core/_mapreduce.py b/rainbowadn/flow/core/_mapreduce.py index 04d9dc3..13bd99c 100644 --- a/rainbowadn/flow/core/_mapreduce.py +++ b/rainbowadn/flow/core/_mapreduce.py @@ -1,12 +1,13 @@ from typing import Any, Callable, Coroutine, Generic, TypeVar from rainbowadn.core import * + from ._mapper import * from ._reduce import * __all__ = ('MapReduce',) -Element = TypeVar('Element') +Element = TypeVar('Element', contravariant=True) Mapped = TypeVar('Mapped') Out = TypeVar('Out') diff --git a/rainbowadn/flow/core/_mapreducer.py b/rainbowadn/flow/core/_mapreducer.py index fd841f7..ed16c2b 100644 --- a/rainbowadn/flow/core/_mapreducer.py +++ b/rainbowadn/flow/core/_mapreducer.py @@ -7,7 +7,7 @@ from ._reducer import * __all__ = ('MapReducer',) -Element = TypeVar('Element') +Element = TypeVar('Element', contravariant=True) Mapped = TypeVar('Mapped') Out = TypeVar('Out') diff --git a/rainbowadn/flow/core/_reduce.py b/rainbowadn/flow/core/_reduce.py index a0b5cca..017e4ea 100644 --- a/rainbowadn/flow/core/_reduce.py +++ b/rainbowadn/flow/core/_reduce.py @@ -4,7 +4,7 @@ from rainbowadn.core import * __all__ = ('Reduce',) -Element = TypeVar('Element') +Element = TypeVar('Element', contravariant=True) Out = TypeVar('Out') diff --git a/rainbowadn/flow/core/_reducer.py b/rainbowadn/flow/core/_reducer.py index 4b8be85..8db4d25 100644 --- a/rainbowadn/flow/core/_reducer.py +++ b/rainbowadn/flow/core/_reducer.py @@ -4,7 +4,7 @@ from ._reduce import * __all__ = ('Reducer',) -Element = TypeVar('Element') +Element = TypeVar('Element', contravariant=True) Out = TypeVar('Out') diff --git a/rainbowadn/flow/primitive/_constmapper.py b/rainbowadn/flow/primitive/_constmapper.py index 776eadc..2e9d9ad 100644 --- a/rainbowadn/flow/primitive/_constmapper.py +++ b/rainbowadn/flow/primitive/_constmapper.py @@ -4,8 +4,8 @@ from rainbowadn.flow.core import * __all__ = ('ConstMapper',) -Element = TypeVar('Element') -Mapped = TypeVar('Mapped') +Element = TypeVar('Element', contravariant=True) +Mapped = TypeVar('Mapped', covariant=True) class ConstMapper(Mapper[Element, Mapped], Generic[Element, Mapped]): diff --git a/rainbowadn/flow/primitive/_unitreducer.py b/rainbowadn/flow/primitive/_unitreducer.py index 6186e88..3ef36d8 100644 --- a/rainbowadn/flow/primitive/_unitreducer.py +++ b/rainbowadn/flow/primitive/_unitreducer.py @@ -4,7 +4,7 @@ from rainbowadn.flow.core import * __all__ = ('UnitReducer',) -Element = TypeVar('Element') +Element = TypeVar('Element', contravariant=True) Out = TypeVar('Out') diff --git a/rainbowadn/flow/verification/core/_compositionverification.py b/rainbowadn/flow/verification/core/_compositionverification.py index 1b05b85..161b3db 100644 --- a/rainbowadn/flow/verification/core/_compositionverification.py +++ b/rainbowadn/flow/verification/core/_compositionverification.py @@ -2,11 +2,12 @@ from typing import Generic, TypeVar from rainbowadn.core import * from rainbowadn.flow.core import * + from ._verification import * __all__ = ('CompositionVerification',) -Verified = TypeVar('Verified') +Verified = TypeVar('Verified', contravariant=True) Middle = TypeVar('Middle') diff --git a/rainbowadn/flow/verification/core/_mapperverification.py b/rainbowadn/flow/verification/core/_mapperverification.py index d9db288..78cd4ae 100644 --- a/rainbowadn/flow/verification/core/_mapperverification.py +++ b/rainbowadn/flow/verification/core/_mapperverification.py @@ -1,11 +1,12 @@ from typing import Generic, TypeVar from rainbowadn.flow.core import * + from ._verification import * __all__ = ('MapperVerification',) -Verified = TypeVar('Verified') +Verified = TypeVar('Verified', contravariant=True) class MapperVerification(Verification[Verified], Generic[Verified]): diff --git a/rainbowadn/flow/verification/core/_reduceverification.py b/rainbowadn/flow/verification/core/_reduceverification.py index 3ec56a2..a1bb666 100644 --- a/rainbowadn/flow/verification/core/_reduceverification.py +++ b/rainbowadn/flow/verification/core/_reduceverification.py @@ -2,12 +2,13 @@ from typing import Generic, TypeVar from rainbowadn.core import * from rainbowadn.flow.core import * + from ._verification import * from ._verifyreduce import * __all__ = ('ReduceVerification',) -Verified = TypeVar('Verified') +Verified = TypeVar('Verified', contravariant=True) class ReduceVerification( diff --git a/rainbowadn/flow/verification/core/_verification.py b/rainbowadn/flow/verification/core/_verification.py index 4439bad..1f2ebac 100644 --- a/rainbowadn/flow/verification/core/_verification.py +++ b/rainbowadn/flow/verification/core/_verification.py @@ -5,7 +5,7 @@ from rainbowadn.flow.core import * __all__ = ('Verification',) -Verified = TypeVar('Verified') +Verified = TypeVar('Verified', contravariant=True) class Verification( diff --git a/rainbowadn/flow/verification/stateverification.py b/rainbowadn/flow/verification/stateverification.py index 8864fce..b228780 100644 --- a/rainbowadn/flow/verification/stateverification.py +++ b/rainbowadn/flow/verification/stateverification.py @@ -5,7 +5,7 @@ from rainbowadn.flow.core import * from rainbowadn.flow.verification.core import * from rainbowadn.nullability import * -__all__ = ('StateVerification',) +__all__ = ('StateVerification', 'SVF',) Header = TypeVar('Header') State = TypeVar('State') @@ -19,7 +19,7 @@ class StateVerification( def __init__( self, mapper: Mapper[Link, tuple[Header, State]], - verification: Verification[tuple[Nullable[State], Header, State]] + verification: Verification[tuple[Nullable[State], Header, State]], ): assert isinstance(mapper, Mapper) assert isinstance(verification, Mapper) @@ -58,3 +58,12 @@ class StateVerification( def loose(self) -> Verification[tuple[Nullable[Link], Link]]: return self + + +class SVF(Generic[Header, State, Link]): + def make( + self, + mapper: Mapper[Link, tuple[Header, State]], + verification: Verification[tuple[Nullable[State], Header, State]], + ) -> Verification[tuple[Nullable[Link], Link]]: + return StateVerification(mapper, verification) diff --git a/rainbowadn/flow13/__init__.py b/rainbowadn/flow13/__init__.py index ff9e82c..e0d571e 100644 --- a/rainbowadn/flow13/__init__.py +++ b/rainbowadn/flow13/__init__.py @@ -12,4 +12,7 @@ from ._flowblock import FlowBlock, FlowBlockFactory, FlowBlockVerification from ._flowcheque import FlowCheque from ._flowiterate import FlowIterate from ._flowstandard import FlowStandard -from ._flowtransaction import FlowCoin, FlowCoinData, FlowTransaction, FlowTransactionData +from ._flowtransaction import ( + FlowCoin, FlowCoinData, FlowTransaction, + FlowTransactionData +) diff --git a/rainbowadn/flow13/_bankblock.py b/rainbowadn/flow13/_bankblock.py index 9974bef..360ed17 100644 --- a/rainbowadn/flow13/_bankblock.py +++ b/rainbowadn/flow13/_bankblock.py @@ -5,6 +5,7 @@ from rainbowadn.flow.core import * from rainbowadn.flow.verification.core import * from rainbowadn.inlining import * from rainbowadn.nullability import * + from ._bankflow import * from ._flowbank import * from ._flowblock import * @@ -42,7 +43,8 @@ class BankBlock: @classmethod def verification(cls) -> Verification[Index]: - return FlowBlockVerification(cls.flow().link_verification()).loose() + fbvf: FBVF[Link] = FBVF() + return fbvf.make(cls.flow().link_verification()) async def verify(self) -> bool: assert_true(await self.verification().verify(await FlowBlock.outer_of(self.link_factory(), self.reference))) diff --git a/rainbowadn/flow13/_bankflow.py b/rainbowadn/flow13/_bankflow.py index 927a6bd..a1faeb1 100644 --- a/rainbowadn/flow13/_bankflow.py +++ b/rainbowadn/flow13/_bankflow.py @@ -8,6 +8,7 @@ from rainbowadn.flow.verification.core import * from rainbowadn.flow.verification.stateverification import * from rainbowadn.inlining import * from rainbowadn.nullability import * + from ._flowbank import * from ._flowcheque import * from ._flowstandard import * @@ -21,7 +22,7 @@ Link: TypeAlias = IPair[FlowCheque, FlowBank] class BankFlow( Verification[ - tuple[Nullable[HashPoint[FlowBank]], HashPoint[FlowCheque], HashPoint[FlowBank]] + tuple[Nullable[FlowBank], FlowCheque, FlowBank] ], ): def __init__(self, initial: FlowBank): @@ -157,12 +158,13 @@ class BankFlow( assert isinstance(bank, FlowBank) return cheque, bank - return StateVerification( + svf: SVF[FlowCheque, FlowBank, HashPoint[Link]] = SVF() + return svf.make( Decomposition(), self.loose() - ).loose() + ) def loose(self) -> Verification[ - tuple[Nullable[HashPoint[FlowBank]], HashPoint[FlowCheque], HashPoint[FlowBank]] + tuple[Nullable[FlowBank], FlowCheque, FlowBank] ]: return self diff --git a/rainbowadn/flow13/_binaryflow.py b/rainbowadn/flow13/_binaryflow.py index 18505f6..2c7e850 100644 --- a/rainbowadn/flow13/_binaryflow.py +++ b/rainbowadn/flow13/_binaryflow.py @@ -9,8 +9,8 @@ from rainbowadn.flow.core import * __all__ = ('BinaryReducer', 'VerifySubsetAction', 'CheckResult',) -KeyT = TypeVar('KeyT') -MetadataT = TypeVar('MetadataT') +KeyT = TypeVar('KeyT', bound=Mentionable) +MetadataT = TypeVar('MetadataT', bound=Mentionable) TreeT = TypeVar('TreeT') Out = TypeVar('Out') @@ -38,7 +38,7 @@ class BinaryReducerAction( BinaryAction[KeyT, MetadataT, TreeT, Out], Generic[KeyT, MetadataT, TreeT, Out], ): - def __init__(self, reduce: Reduce[KeyT, Out]): + def __init__(self, reduce: Reduce[HashPoint[KeyT], Out]): assert isinstance(reduce, Reduce) self.reduce = reduce diff --git a/rainbowadn/flow13/_flowbank.py b/rainbowadn/flow13/_flowbank.py index 69c965a..fbd982d 100644 --- a/rainbowadn/flow13/_flowbank.py +++ b/rainbowadn/flow13/_flowbank.py @@ -2,6 +2,7 @@ from typing import Iterable from rainbowadn.collection.comparison import * from rainbowadn.core import * + from ._flowstandard import * from ._flowtransaction import * diff --git a/rainbowadn/flow13/_flowblock.py b/rainbowadn/flow13/_flowblock.py index 0f46b25..4554171 100644 --- a/rainbowadn/flow13/_flowblock.py +++ b/rainbowadn/flow13/_flowblock.py @@ -1,17 +1,15 @@ -from typing import Generic, Iterable, TypeAlias, TypeVar +from typing import Callable, Generic, Iterable, TypeAlias, TypeVar from rainbowadn.collection.comparison import * from rainbowadn.core import * from rainbowadn.flow.verification.core import * from rainbowadn.nullability import * + from ._flowstandard import * -__all__ = ('FlowBlock', 'FlowBlockFactory', 'FlowBlockVerification',) +__all__ = ('FlowBlock', 'FlowBlockFactory', 'FlowBlockVerification', 'FBVF',) -LinkT = TypeVar('LinkT') - -FBL: TypeAlias = 'FlowBlock[LinkT]' -Index: TypeAlias = FlowStandard[FBL] +LinkT = TypeVar('LinkT', bound=Mentionable) class FlowBlock(Generic[LinkT], RecursiveMentionable): @@ -21,13 +19,13 @@ class FlowBlock(Generic[LinkT], RecursiveMentionable): def __bytes__(self): return bytes(self.previous) + bytes(self.index) + bytes(self.link) - def __factory__(self) -> RainbowFactory[FBL]: + def __factory__(self) -> RainbowFactory['FBL']: return FlowBlockFactory(self.link.factory) def __init__( self, - previous: NullableReference[FBL], - index: Index, + previous: NullableReference['FBL'], + index: 'Index', link: HashPoint[LinkT], ): assert isinstance(previous, NullableReference) @@ -36,7 +34,7 @@ class FlowBlock(Generic[LinkT], RecursiveMentionable): self.index = index self.link = link - async def outer(self) -> Index: + async def outer(self) -> 'Index': return FlowStandard( ( await self.index.protocolized.tree.add( @@ -45,25 +43,25 @@ class FlowBlock(Generic[LinkT], RecursiveMentionable): ).protocolized() ) - async def verify_outer_matches(self, index: Index) -> bool: + async def verify_outer_matches(self, index: 'Index') -> bool: assert_eq(await self.outer(), index) return True @classmethod - async def outer_of(cls, factory: RainbowFactory[LinkT], reference: NullableReference[FBL]) -> Index: + async def outer_of(cls, factory: RainbowFactory[LinkT], reference: NullableReference['FBL']) -> 'Index': if reference.null(): return FlowStandardFactory.empty(FlowBlockFactory(factory), HashComparator(Fail())) else: return await (await reference.resolve()).outer() @classmethod - async def link_of(cls, reference: NullableReference[FBL]) -> Nullable[LinkT]: + async def link_of(cls, reference: NullableReference['FBL']) -> Nullable[LinkT]: if reference.null(): return Null() else: return NotNull(await (await reference.resolve()).link.resolve()) - async def add(self, link: HashPoint[LinkT]) -> FBL: + async def add(self, link: HashPoint[LinkT]) -> 'FBL': return FlowBlock( NullableReference.off(self), await self.outer(), @@ -71,7 +69,7 @@ class FlowBlock(Generic[LinkT], RecursiveMentionable): ) @classmethod - async def add_to(cls, reference: NullableReference[FBL], link: HashPoint[LinkT]) -> FBL: + async def add_to(cls, reference: NullableReference['FBL'], link: HashPoint[LinkT]) -> 'FBL': return FlowBlock( reference, await cls.outer_of(link.factory, reference), @@ -93,12 +91,12 @@ class FlowBlock(Generic[LinkT], RecursiveMentionable): f'{tabulate(tab)}{link_str}' -class FlowBlockFactory(RainbowFactory[FBL], Generic[LinkT]): +class FlowBlockFactory(RainbowFactory['FBL'], Generic[LinkT]): def __init__(self, factory: RainbowFactory[LinkT]): assert isinstance(factory, RainbowFactory) self.factory = factory - def from_bytes(self, source: bytes, resolver: HashResolver) -> FBL: + def from_bytes(self, source: bytes, resolver: HashResolver) -> 'FBL': assert isinstance(source, bytes) assert isinstance(resolver, HashResolver) return FlowBlock( @@ -109,10 +107,14 @@ class FlowBlockFactory(RainbowFactory[FBL], Generic[LinkT]): ResolverOrigin(self.factory, source[2 * HashPoint.HASH_LENGTH:], resolver).hash_point(), ) - def loose(self) -> RainbowFactory[FBL]: + def loose(self) -> RainbowFactory['FBL']: return self +FBL: TypeAlias = 'FlowBlock[LinkT]' +Index: TypeAlias = FlowStandard[FBL] + + class FlowBlockIndexedVerification( Verification[HashPoint[FBL]], Generic[LinkT] @@ -196,3 +198,11 @@ class FlowBlockVerification( def loose(self) -> Verification[Index]: return self + + +class FBVF(Generic[LinkT]): + def make( + self, + verification: Verification[tuple[Nullable[HashPoint[LinkT]], HashPoint[LinkT]]] + ) -> Verification[Index]: + return FlowBlockVerification(verification) diff --git a/rainbowadn/flow13/_flowcheque.py b/rainbowadn/flow13/_flowcheque.py index 13f2ee0..49f2e47 100644 --- a/rainbowadn/flow13/_flowcheque.py +++ b/rainbowadn/flow13/_flowcheque.py @@ -7,6 +7,7 @@ from rainbowadn.core import * from rainbowadn.flow.core import * from rainbowadn.flow.verification.core import * from rainbowadn.v13 import * + from ._flowiterate import * from ._flowstandard import * from ._flowtransaction import * @@ -76,7 +77,7 @@ class FlowCheque(StaticMentionable, RecursiveMentionable): @classmethod async def total_of(cls, tree: FlowStandard[FlowCoin]) -> int: assert isinstance(tree, FlowStandard) - reducer: Reducer[HashPoint[FlowCoin]] = await tree.reducer() + reducer: Reducer[HashPoint[FlowCoin], int] = await tree.reducer() assert isinstance(reducer, Reducer) total: int = await reducer.reduce(MapReduce(ValueMapper(), SumReduce(0))) assert isinstance(total, int) diff --git a/rainbowadn/flow13/_flowstandard.py b/rainbowadn/flow13/_flowstandard.py index 8decbc3..0099e6e 100644 --- a/rainbowadn/flow13/_flowstandard.py +++ b/rainbowadn/flow13/_flowstandard.py @@ -11,20 +11,20 @@ from rainbowadn.flow.primitive import * from rainbowadn.flow.verification.core import * from rainbowadn.inlining import * from rainbowadn.nullability import * + from ._binaryflow import * from ._flowtree import * __all__ = ('FlowStandard', 'FlowStandardFactory',) -KeyT = TypeVar('KeyT') -FS: TypeAlias = 'FlowStandard[KeyT]' +KeyT = TypeVar('KeyT', bound=Mentionable) ABT: TypeAlias = 'ActiveBinaryTree[KeyT, Integer]' BP: TypeAlias = 'BinaryProtocolized[KeyT, Integer, ABT]' class FlowStandard( RecursiveMentionable, - FlowTree[HashPoint[KeyT], FS], + FlowTree[HashPoint[KeyT], 'FS'], Generic[KeyT] ): def points(self) -> Iterable[HashPoint]: @@ -46,14 +46,14 @@ class FlowStandard( async def contains(self, key: HashPoint[KeyT], *, exact: bool) -> bool: return await self.protocolized.tree.contains(key, exact=exact) - def _protocolized(self: FS) -> BP: + def _protocolized(self: 'FS') -> BP: return self.protocolized @classmethod - def _protocolized_mapper(cls) -> Mapper[FS, BP]: - return CallableMapper(cls._protocolized) + def _protocolized_mapper(cls) -> Mapper['FS', BP]: + return CallableMapper(FlowStandard._protocolized) - async def verify_subset(self, trees: Reducer[FS, CheckResult]) -> bool: + async def verify_subset(self, trees: Reducer['FS', CheckResult]) -> bool: assert isinstance(trees, Reducer) reducer: Reducer[BP, CheckResult] = MapReducer(self._protocolized_mapper(), trees) assert_true(await VerifySubsetAction(reducer).on(self.protocolized)) @@ -83,6 +83,9 @@ class FlowStandard( return await self.protocolized.tree.reference.str(tab) +FS: TypeAlias = 'FlowStandard[KeyT]' + + class FlowStandardFactory(Inlining[FlowStandard[KeyT]], Generic[KeyT]): def __init__( self, diff --git a/rainbowadn/flow13/_flowtransaction.py b/rainbowadn/flow13/_flowtransaction.py index 6724237..4187320 100644 --- a/rainbowadn/flow13/_flowtransaction.py +++ b/rainbowadn/flow13/_flowtransaction.py @@ -9,6 +9,7 @@ from rainbowadn.core import * from rainbowadn.flow.core import * from rainbowadn.flow.verification.core import * from rainbowadn.v13 import * + from ._flowstandard import * from ._resolvemapper import * diff --git a/rainbowadn/flow13/_flowunion.py b/rainbowadn/flow13/_flowunion.py index 8b638a0..96d539b 100644 --- a/rainbowadn/flow13/_flowunion.py +++ b/rainbowadn/flow13/_flowunion.py @@ -1,10 +1,12 @@ from typing import TypeVar +from rainbowadn.core import * + from ._flowstandard import * __all__ = ('flow_union',) -KeyT = TypeVar('KeyT') +KeyT = TypeVar('KeyT', bound=Mentionable) async def flow_union(left: FlowStandard[KeyT], right: FlowStandard[KeyT]) -> FlowStandard[KeyT]: diff --git a/rainbowadn/flow13/_resolvemapper.py b/rainbowadn/flow13/_resolvemapper.py index cdd6c63..4d81eed 100644 --- a/rainbowadn/flow13/_resolvemapper.py +++ b/rainbowadn/flow13/_resolvemapper.py @@ -5,7 +5,7 @@ from rainbowadn.flow.core import * __all__ = ('ResolveMapper',) -MentionedT = TypeVar('MentionedT') +MentionedT = TypeVar('MentionedT', bound=Mentionable) Out = TypeVar('Out') diff --git a/rainbowadn/inlining/iatomic.py b/rainbowadn/inlining/iatomic.py index 8037b46..bfed36d 100644 --- a/rainbowadn/inlining/iatomic.py +++ b/rainbowadn/inlining/iatomic.py @@ -2,6 +2,7 @@ import abc from typing import Type, TypeVar from rainbowadn.core import * + from .istatic import * __all__ = ('IAtomic',) diff --git a/rainbowadn/inlining/iauto.py b/rainbowadn/inlining/iauto.py index 8a9059b..b1052ff 100644 --- a/rainbowadn/inlining/iauto.py +++ b/rainbowadn/inlining/iauto.py @@ -1,7 +1,11 @@ import heapq -from typing import Callable, Generic, Iterable, Optional, Type, TypeAlias, TypeVar, overload +from typing import ( + Callable, Generic, Iterable, Optional, Type, TypeAlias, + TypeVar, overload +) from rainbowadn.core import * + from .inlining import * __all__ = ('IAuto', 'Auto', 'IAutoFactory',) @@ -12,7 +16,7 @@ _SList: TypeAlias = list[tuple[int, RainbowFactory, int]] _VList: TypeAlias = list[tuple[int, RainbowFactory]] _MCall: TypeAlias = Callable[['Auto', _IList, _UList], None] _MTuple: TypeAlias = tuple[int, _MCall, int] -_IAuto = TypeVar('_IAuto') +_IAuto = TypeVar('_IAuto', bound='IAuto') class IAuto(RecursiveMentionable): @@ -58,7 +62,6 @@ class IAuto(RecursiveMentionable): return b''.join(source for _, source in merged_bytes) def __factory__(self: _IAuto) -> RainbowFactory[_IAuto]: - assert isinstance(self, IAuto) sized: _SList = [] inlined_unsized: _VList = [] uninlined_unsized: _VList = [] @@ -156,12 +159,12 @@ class IAuto(RecursiveMentionable): return f'{tabulate(tab)}'.join(formatted) -T = TypeVar('T') -T0 = TypeVar('T0') -T1 = TypeVar('T1') -T2 = TypeVar('T2') -T3 = TypeVar('T3') -T4 = TypeVar('T4') +T = TypeVar('T', bound=Mentionable) +T0 = TypeVar('T0', bound=Mentionable) +T1 = TypeVar('T1', bound=Mentionable) +T2 = TypeVar('T2', bound=Mentionable) +T3 = TypeVar('T3', bound=Mentionable) +T4 = TypeVar('T4', bound=Mentionable) class Auto: @@ -197,9 +200,16 @@ class Auto: self.__index += size return self.sub(index, self.__index) + @classmethod + def _force_size(cls, factory: RainbowFactory) -> int: + size = Inlining.factory_size(factory) + if size is None: + raise ValueError + return size + @classmethod def _static_size(cls, *factories: RainbowFactory) -> int: - return sum(Inlining.factory_size(factory) for factory in factories) + return sum(cls._force_size(factory) for factory in factories) def _static_simple(self, *factories: RainbowFactory) -> Iterable[Mentionable]: with self: @@ -234,32 +244,32 @@ class Auto: @overload def static( - self, t0: RainbowFactory[T0] + self, t0: RainbowFactory[T0], / ) -> tuple[T0]: ... @overload def static( - self, t0: RainbowFactory[T0], t1: RainbowFactory[T1] + self, t0: RainbowFactory[T0], t1: RainbowFactory[T1], / ) -> tuple[T0, T1]: ... @overload def static( - self, t0: RainbowFactory[T0], t1: RainbowFactory[T1], t2: RainbowFactory[T2] + self, t0: RainbowFactory[T0], t1: RainbowFactory[T1], t2: RainbowFactory[T2], / ) -> tuple[T0, T1, T2]: ... @overload def static( - self, t0: RainbowFactory[T0], t1: RainbowFactory[T1], t2: RainbowFactory[T2], t3: RainbowFactory[T3] + self, t0: RainbowFactory[T0], t1: RainbowFactory[T1], t2: RainbowFactory[T2], t3: RainbowFactory[T3], / ) -> tuple[T0, T1, T2, T3]: ... @overload def static( self, t0: RainbowFactory[T0], t1: RainbowFactory[T1], t2: RainbowFactory[T2], t3: RainbowFactory[T3], - t4: RainbowFactory[T4] + t4: RainbowFactory[T4], / ) -> tuple[T0, T1, T2, T3, T4]: ... @@ -267,7 +277,7 @@ class Auto: return tuple(self._static(*factories)) -class IAutoFactory(Inlining[IAuto], Generic[_IAuto]): +class IAutoFactory(Inlining[_IAuto], Generic[_IAuto]): def __init__( self, typed: Type[_IAuto], diff --git a/rainbowadn/inlining/inlining.py b/rainbowadn/inlining/inlining.py index 201a1bd..2acc084 100644 --- a/rainbowadn/inlining/inlining.py +++ b/rainbowadn/inlining/inlining.py @@ -5,7 +5,7 @@ from rainbowadn.core import * __all__ = ('Inlining',) -Inlined = TypeVar('Inlined') +Inlined = TypeVar('Inlined', bound=Mentionable, covariant=True) _FTuple: TypeAlias = tuple[int, Callable[[bytes, HashResolver], HashPoint], int] _HTuple: TypeAlias = tuple[int, Callable[[], Coroutine[Any, Any, bytes]]] diff --git a/rainbowadn/inlining/ipair.py b/rainbowadn/inlining/ipair.py index d219e2c..c78ab0b 100644 --- a/rainbowadn/inlining/ipair.py +++ b/rainbowadn/inlining/ipair.py @@ -1,12 +1,13 @@ from typing import Generic, TypeVar from rainbowadn.core import * + from .iauto import * __all__ = ('IPair',) -E0 = TypeVar('E0') -E1 = TypeVar('E1') +E0 = TypeVar('E0', bound=Mentionable) +E1 = TypeVar('E1', bound=Mentionable) class IPair(IAuto, Generic[E0, E1]): diff --git a/rainbowadn/inlining/iref.py b/rainbowadn/inlining/iref.py index 02fae3b..3f2a70b 100644 --- a/rainbowadn/inlining/iref.py +++ b/rainbowadn/inlining/iref.py @@ -1,11 +1,12 @@ from typing import Generic, Iterable, Optional, TypeVar from rainbowadn.core import * + from .inlining import * __all__ = ('IRef',) -TRef = TypeVar('TRef') +TRef = TypeVar('TRef', bound=Mentionable) class IRef(RecursiveMentionable, Generic[TRef]): diff --git a/rainbowadn/inlining/istatic.py b/rainbowadn/inlining/istatic.py index bfc1cbf..66f14fd 100644 --- a/rainbowadn/inlining/istatic.py +++ b/rainbowadn/inlining/istatic.py @@ -2,11 +2,12 @@ import abc from typing import Generic, Optional, Type, TypeVar from rainbowadn.core import * + from .inlining import * __all__ = ('IStatic', 'IStaticFactory',) -StaticInlined = TypeVar('StaticInlined') +StaticInlined = TypeVar('StaticInlined', bound='IStatic') class IStatic(Mentionable, abc.ABC): diff --git a/rainbowadn/inlining/iunit.py b/rainbowadn/inlining/iunit.py index 5dca36e..37a8a56 100644 --- a/rainbowadn/inlining/iunit.py +++ b/rainbowadn/inlining/iunit.py @@ -1,4 +1,5 @@ from rainbowadn.core import * + from .iatomic import * __all__ = ('IUnit',) diff --git a/rainbowadn/nullability/notnull.py b/rainbowadn/nullability/notnull.py index 7fc5036..f4cdeee 100644 --- a/rainbowadn/nullability/notnull.py +++ b/rainbowadn/nullability/notnull.py @@ -4,7 +4,7 @@ from .nullable import * __all__ = ('NotNull',) -NullableType = TypeVar('NullableType') +NullableType = TypeVar('NullableType', covariant=True) class NotNull(Nullable[NullableType], Generic[NullableType]): diff --git a/rainbowadn/nullability/null.py b/rainbowadn/nullability/null.py index 64b0105..9f3b4af 100644 --- a/rainbowadn/nullability/null.py +++ b/rainbowadn/nullability/null.py @@ -4,7 +4,7 @@ from .nullable import * __all__ = ('Null',) -NullableType = TypeVar('NullableType') +NullableType = TypeVar('NullableType', covariant=True) class Null(Nullable[NullableType], Generic[NullableType]): diff --git a/rainbowadn/nullability/nullable.py b/rainbowadn/nullability/nullable.py index 4a0cc21..515091b 100644 --- a/rainbowadn/nullability/nullable.py +++ b/rainbowadn/nullability/nullable.py @@ -3,7 +3,7 @@ from typing import Generic, TypeVar __all__ = ('Nullable',) -NullableType = TypeVar('NullableType') +NullableType = TypeVar('NullableType', covariant=True) class Nullable(Generic[NullableType], abc.ABC): diff --git a/rainbowadn/nullability/nullablereference.py b/rainbowadn/nullability/nullablereference.py index d79761d..8404a53 100644 --- a/rainbowadn/nullability/nullablereference.py +++ b/rainbowadn/nullability/nullablereference.py @@ -2,13 +2,15 @@ from typing import Generic, Iterable, Optional, TypeVar from rainbowadn.core import * from rainbowadn.inlining import * + from .notnull import * from .null import * from .nullable import * __all__ = ('NullableReference', 'NullableReferenceFactory',) -Referenced = TypeVar('Referenced') +Referenced = TypeVar('Referenced', bound=Mentionable, covariant=True) +ReferencedI = TypeVar('ReferencedI', bound=Mentionable) class NullableReference(RecursiveMentionable, Generic[Referenced]): @@ -41,7 +43,7 @@ class NullableReference(RecursiveMentionable, Generic[Referenced]): return cls(NotNull(hash_point), hash_point.factory) @classmethod - def off(cls, value: Referenced) -> 'NullableReference[Referenced]': + def off(cls, value: ReferencedI) -> 'NullableReference[ReferencedI]': assert isinstance(value, Mentionable) return cls.of(HashPoint.of(value)) diff --git a/rainbowadn/testing/resolvers/cachingresolver.py b/rainbowadn/testing/resolvers/cachingresolver.py index 29a824f..dbc5843 100644 --- a/rainbowadn/testing/resolvers/cachingresolver.py +++ b/rainbowadn/testing/resolvers/cachingresolver.py @@ -4,7 +4,7 @@ from rainbowadn.core import * __all__ = ('CachingResolver',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable) class CachingResolver(ExtendableResolver): diff --git a/rainbowadn/testing/resolvers/delayedresolver.py b/rainbowadn/testing/resolvers/delayedresolver.py index 8263400..4d0479d 100644 --- a/rainbowadn/testing/resolvers/delayedresolver.py +++ b/rainbowadn/testing/resolvers/delayedresolver.py @@ -5,7 +5,7 @@ from rainbowadn.core import * __all__ = ('DelayedResolver',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable) class DelayedResolver(ExtendableResolver): diff --git a/rainbowadn/testing/resolvers/dictresolver.py b/rainbowadn/testing/resolvers/dictresolver.py index 679de13..9ea977c 100644 --- a/rainbowadn/testing/resolvers/dictresolver.py +++ b/rainbowadn/testing/resolvers/dictresolver.py @@ -5,7 +5,7 @@ from rainbowadn.core import * __all__ = ('DictResolver',) -Mentioned = TypeVar('Mentioned') +Mentioned = TypeVar('Mentioned', bound=Mentionable) class DictResolver(ExtendableResolver): diff --git a/rainbowadn/testing/test_bridge.py b/rainbowadn/testing/test_bridge.py index 3d9dd7f..77df220 100644 --- a/rainbowadn/testing/test_bridge.py +++ b/rainbowadn/testing/test_bridge.py @@ -9,9 +9,9 @@ from rainbowadn.atomic import * from rainbowadn.collection.comparison import * from rainbowadn.collection.trees.binary import * from rainbowadn.core import * +from rainbowadn.flow13 import * from rainbowadn.flow.bridge import * from rainbowadn.flow.primitive import * -from rainbowadn.flow13 import * from rainbowadn.v13 import * diff --git a/rainbowadn/testing/test_inlining.py b/rainbowadn/testing/test_inlining.py index 9496174..bb69d71 100644 --- a/rainbowadn/testing/test_inlining.py +++ b/rainbowadn/testing/test_inlining.py @@ -3,6 +3,7 @@ import unittest from rainbowadn.atomic import * from rainbowadn.core import * from rainbowadn.inlining import * + from .resolvers import * diff --git a/rainbowadn/toplevel/validreference.py b/rainbowadn/toplevel/validreference.py index 32d9726..a1e75da 100644 --- a/rainbowadn/toplevel/validreference.py +++ b/rainbowadn/toplevel/validreference.py @@ -1,11 +1,12 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.core import * + from .thresholdprotocol import * __all__ = ('ValidReference', 'ValidReferenceFactory') -Referenced = TypeVar('Referenced') +Referenced = TypeVar('Referenced', bound=Mentionable) class ValidReference(RecursiveMentionable, Generic[Referenced]): diff --git a/rainbowadn/v13/signature.py b/rainbowadn/v13/signature.py index 127909f..458e874 100644 --- a/rainbowadn/v13/signature.py +++ b/rainbowadn/v13/signature.py @@ -4,6 +4,7 @@ import nacl.signing from rainbowadn.core import * from rainbowadn.inlining import * + from .subject import * __all__ = ('BadSignature', 'Signature',) diff --git a/rainbowadn/wrisbt/weakreferenceindexsetbtree.py b/rainbowadn/wrisbt/weakreferenceindexsetbtree.py index 36e862d..616592d 100644 --- a/rainbowadn/wrisbt/weakreferenceindexsetbtree.py +++ b/rainbowadn/wrisbt/weakreferenceindexsetbtree.py @@ -2,6 +2,7 @@ import bisect from typing import AsyncIterable, Iterable, Sequence from rainbowadn.core import * + from .wrisbtparametres import * __all__ = ('WeakReferenceIndexSetBTree', 'WrisbtFactory',) @@ -222,47 +223,47 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable): assert isinstance(right, WeakReferenceIndexSetBTree) return WeakReferenceIndexSetBTree( ( - self.source[:self.keysize * index] - + - middle - + - self.source[self.keysize * index:self.keyend + HashPoint.HASH_LENGTH * index] - + - bytes(HashPoint.of(left)) - + - bytes(HashPoint.of(right)) - + - self.source[self.keyend + HashPoint.HASH_LENGTH * (index + 1):] + self.source[:self.keysize * index] + + + middle + + + self.source[self.keysize * index:self.keyend + HashPoint.HASH_LENGTH * index] + + + bytes(HashPoint.of(left)) + + + bytes(HashPoint.of(right)) + + + self.source[self.keyend + HashPoint.HASH_LENGTH * (index + 1):] ), self.height, self.parametres, self.root, ( - self.cache[:index] - + - (LocalMetaOrigin(LocalOrigin(left)), LocalMetaOrigin(LocalOrigin(right))) - + - self.cache[index + 1:] + self.cache[:index] + + + (LocalMetaOrigin(LocalOrigin(left)), LocalMetaOrigin(LocalOrigin(right))) + + + self.cache[index + 1:] ) ) else: return WeakReferenceIndexSetBTree( ( - self.source[:self.keyend + HashPoint.HASH_LENGTH * index] - + - bytes(HashPoint.of(child)) - + - self.source[self.keyend + HashPoint.HASH_LENGTH * (index + 1):] + self.source[:self.keyend + HashPoint.HASH_LENGTH * index] + + + bytes(HashPoint.of(child)) + + + self.source[self.keyend + HashPoint.HASH_LENGTH * (index + 1):] ), self.height, self.parametres, self.root, ( - self.cache[:index] - + - (LocalMetaOrigin(LocalOrigin(child)),) - + - self.cache[index + 1:] + self.cache[:index] + + + (LocalMetaOrigin(LocalOrigin(child)),) + + + self.cache[index + 1:] ) ) diff --git a/rainbowadn/wrisbt/wrisbtindex.py b/rainbowadn/wrisbt/wrisbtindex.py index f83d779..c94c189 100644 --- a/rainbowadn/wrisbt/wrisbtindex.py +++ b/rainbowadn/wrisbt/wrisbtindex.py @@ -1,6 +1,7 @@ from typing import Iterable from rainbowadn.core import * + from .wrisbtparametres import * from .wrisbtroot import * diff --git a/rainbowadn/wrisbt/wrisbtroot.py b/rainbowadn/wrisbt/wrisbtroot.py index d212ab7..0f20eef 100644 --- a/rainbowadn/wrisbt/wrisbtroot.py +++ b/rainbowadn/wrisbt/wrisbtroot.py @@ -2,6 +2,7 @@ from typing import Iterable from rainbowadn.atomic import * from rainbowadn.core import * + from .weakreferenceindexsetbtree import * from .wrisbtparametres import * diff --git a/trace_common.py b/trace_common.py index dcd03e1..ad2d371 100644 --- a/trace_common.py +++ b/trace_common.py @@ -29,6 +29,8 @@ def target_str(target) -> str: return name case object(__class__=type(__name__=name)): return name + case _: + raise TypeError def jsonify(dumped: Instrumentation) -> dict: diff --git a/trace_flow.py b/trace_flow.py index f97684e..962ebf3 100644 --- a/trace_flow.py +++ b/trace_flow.py @@ -4,8 +4,9 @@ from contextlib import ExitStack from typing import Any, Callable, Coroutine from nacl.signing import SigningKey, VerifyKey - from plot import * +from trace_common import * + from rainbowadn.collection.trees.binary import * from rainbowadn.core import * from rainbowadn.flow13 import * @@ -13,7 +14,6 @@ from rainbowadn.flow13 import FlowCoin from rainbowadn.instrument import * from rainbowadn.testing.resolvers import * from rainbowadn.v13 import * -from trace_common import * def get_instrumentations() -> list[Instrumentation]: @@ -91,8 +91,8 @@ async def _migrate(bank: BankBlock, params) -> BankBlock: async def _instrument(process: Callable[[], Coroutine[Any, Any, None]]) -> list[Instrumentation]: + instrumentations: list[Instrumentation] = get_instrumentations() with ExitStack() as estack: - instrumentations: list[Instrumentation] = get_instrumentations() for stacked in instrumentations: stacked.enter(estack) try: @@ -167,7 +167,7 @@ if __name__ == '__main__': try: asyncio.run( trace( - preset_long + preset_short ) ) except KeyboardInterrupt: