Collection(MutableSet, Hashable)¶
-
class
metaknowledge.Collection(inSet, allowedTypes, collectedTypes, name, bad, errors, quietStart=False)¶ A named hashable set with some error reporting.
Collectionshave all the methods of builtinsetsas well as error reporting with bad and error, and control over the contained items with allowedTypes and collectedTypes.Customizations¶
When created name should be a string that allows users to easily determine the source of the
CollectionWhen created the you must provided a set of types, allowedTypes, when new items are added they will be checked and if they are not instances of any of the types an
CollectionTypeErrorexception will be raised. The collectedTypes set that is provided should be a set of only the types in theCollection.If any of the elements in the
Collectionare bad then bad should be set toTrueand thedicterrors should map the item to it’s exception.All of these customizations are managed when operations occur on the
Collectionand if 2Collectionsare modified with one of the binary operators (|,-, etc) the_collectedTypesanderrorsattributes will be modified the same way.namewill be updated to explain the operation(s) that occurred.__Init__
As
Collectionis mostly meant to be base for other classes all but one of the arguments in the __Init__ are not optional and the optional one is not used.Parameters¶
inSet :
setThe objects to be containedallowedTypes :
set[type]A set of types,{object}will allow virtually everythingcollectedTypes :
set[type]The types (or supertypes) of the objects in inSetname :
strThe name of theCollectionbad :
boolIf any of the elements are baderrors :
dict[:Exception]A mapping from items to their errorsquietStart :
optional [bool]DefaultFalse, does nothing. This is here for use as a interface by subclasses-
__eq__(other)¶ Return self==value.
-
__ge__(other)¶ Return self>=value.
-
__hash__()¶ Return hash(self).
-
__init__(inSet, allowedTypes, collectedTypes, name, bad, errors, quietStart=False)¶ Basically a collections.abc.MutableSet wrapper for a set with a bunch of extra record keeping attached.
-
__le__(other)¶ Return self<=value.
-
__repr__()¶ Return repr(self).
-
__str__()¶ Return str(self).
-
__weakref__¶ list of weak references to the object (if defined)
-
add(elem)¶ Adds elem to the collection.
-
chunk(maxSize)¶ Splits the
Collectioninto maxSize size or smallerCollections
-
clear()¶ “Removes all elements from the collection and resets the error handling
-
copy()¶ Creates a shallow copy of the collection
-
discard(elem)¶ Removes elem from the collection, will not raise an Exception if elem is missing
-
peek()¶ returns a random element from the collection. If ran twice the same element will usually be returned
-
pop()¶ Removes a random element from the collection and returns it
-
remove(elem)¶ Removes elem from the collection, will raise a KeyError is elem is missing
-
split(maxSize)¶ Destructively, splits the
Collectioninto maxSize size or smallerCollections. The sourceCollectionwill be empty after this operation
-