slidge.util
#
Submodules#
Package Contents#
Classes#
Metaclass for defining Abstract Base Classes (ABCs). |
|
Abstract base class for generic types. |
|
Functions#
|
- class slidge.util.ABCSubclassableOnceAtMost(name, bases, dct)[source]#
Bases:
abc.ABCMeta
,SubclassableOnce
Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as ‘virtual subclasses’ – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).
- class slidge.util.BiDict(*args, **kwargs)[source]#
Bases:
Generic
[KeyType
,ValueType
],dict
[KeyType
,ValueType
]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
Initialize self. See help(type(self)) for accurate signature.
- __setitem__(key, value)#
Set self[key] to value.
- Parameters:
key (KeyType) –
value (ValueType) –