checksum_dict package
Submodules
checksum_dict.base module
- class checksum_dict.base.ChecksumAddressDict
Bases:
dict[ChecksumAddress,T]- classmethod __class_getitem__(object, /)
See PEP 585
- __contains__(key, /)
True if the dictionary has the specified key, else False.
- __delitem__(key, /)
Delete self[key].
- __eq__(value, /)
Return self==value.
- __ge__(value, /)
Return self>=value.
- __getitem__(key, /)
Return self[key].
- __getstate__()
Helper for pickle.
- __gt__(value, /)
Return self>value.
- __init__(*args, **kwargs)
- __ior__(value, /)
Return self|=value.
- __iter__()
Implement iter(self).
- __le__(value, /)
Return self<=value.
- __len__()
Return len(self).
- __lt__(value, /)
Return self<value.
- __ne__(value, /)
Return self!=value.
- classmethod __new__(*args, **kwargs)
- __or__(value, /)
Return self|value.
- __repr__()
Return repr(self).
- __reversed__()
Return a reverse iterator over the dict keys.
- __ror__(value, /)
Return value|self.
- __setitem__(key, value, /)
Set self[key] to value.
- __setstate__(object, /)
- __sizeof__()
Return the size of the dict in memory, in bytes.
- clear()
Remove all items from the dict.
- copy()
Return a shallow copy of the dict.
- classmethod fromkeys(iterable, value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- __dict__ = mappingproxy({'__orig_bases__': (dict[eth_typing.evm.ChecksumAddress, ~T],), '__repr__': <slot wrapper '__repr__' of 'ChecksumAddressDict' objects>, '__init__': <slot wrapper '__init__' of 'ChecksumAddressDict' objects>, '__getitem__': <slot wrapper '__getitem__' of 'ChecksumAddressDict' objects>, '__setitem__': <slot wrapper '__setitem__' of 'ChecksumAddressDict' objects>, '__delitem__': <slot wrapper '__delitem__' of 'ChecksumAddressDict' objects>, '_getitem_nochecksum': <method '_getitem_nochecksum' of 'ChecksumAddressDict' objects>, '_setitem_nochecksum': <method '_setitem_nochecksum' of 'ChecksumAddressDict' objects>, '__setstate__': <method '__setstate__' of 'ChecksumAddressDict' objects>, '__getstate__': <method '__getstate__' of 'ChecksumAddressDict' objects>, '__dict__': <attribute '__dict__' of 'ChecksumAddressDict' objects>, '__doc__': '', '__module__': 'checksum_dict.base', '__mypyc_attrs__': ('__dict__',), '__annotations_cache__': {}})
- __hash__ = None
- __module__ = 'checksum_dict.base'
- __mypyc_attrs__ = ('__dict__',)
- __orig_bases__ = (dict[eth_typing.evm.ChecksumAddress, ~T],)
checksum_dict.default module
- class checksum_dict.default.DefaultChecksumDict
Bases:
DefaultDict[ChecksumAddress,T],ChecksumAddressDict[T]- classmethod __class_getitem__(object, /)
See PEP 585
- __contains__(key, /)
True if the dictionary has the specified key, else False.
- __copy__()
D.copy() -> a shallow copy of D.
- __delitem__(key, /)
Delete self[key].
- __eq__(value, /)
Return self==value.
- __ge__(value, /)
Return self>=value.
- __getattribute__(name, /)
Return getattr(self, name).
- __getitem__(key, /)
Return self[key].
- __getstate__()
Helper for pickle.
- __gt__(value, /)
Return self>value.
- __init__(*args, **kwargs)
- classmethod __init_subclass__()
Function to initialize subclasses.
- __ior__(value, /)
Return self|=value.
- __iter__()
Implement iter(self).
- __le__(value, /)
Return self<=value.
- __len__()
Return len(self).
- __lt__(value, /)
Return self<value.
- __missing__(object, /)
__missing__(key) # Called by __getitem__ for missing key; pseudo-code: if self.default_factory is None: raise KeyError((key,)) self[key] = value = self.default_factory() return value
- __ne__(value, /)
Return self!=value.
- classmethod __new__(*args, **kwargs)
- __or__(value, /)
Return self|value.
- __reduce__()
Return state information for pickling.
- __repr__()
Return repr(self).
- __reversed__()
Return a reverse iterator over the dict keys.
- __ror__(value, /)
Return value|self.
- __setitem__(key, value, /)
Set self[key] to value.
- __setstate__(object, /)
- __sizeof__()
Return the size of the dict in memory, in bytes.
- clear()
Remove all items from the dict.
- copy() a shallow copy of D.
- classmethod fromkeys(iterable, value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- __annotations_cache__ = {}
- __dict__ = mappingproxy({'__orig_bases__': (typing.DefaultDict[eth_typing.evm.ChecksumAddress, ~T], checksum_dict.base.ChecksumAddressDict[~T]), '__init__': <slot wrapper '__init__' of 'DefaultChecksumDict' objects>, '_getitem_nochecksum': <method '_getitem_nochecksum' of 'DefaultChecksumDict' objects>, '__setstate__': <method '__setstate__' of 'DefaultChecksumDict' objects>, '__getstate__': <method '__getstate__' of 'DefaultChecksumDict' objects>, '__dict__': <attribute '__dict__' of 'DefaultChecksumDict' objects>, '__doc__': '', '__module__': 'checksum_dict.default', '__parameters__': (~T,), '__mypyc_attrs__': ('__dict__',), '__annotations_cache__': {}})
- __hash__ = None
- __module__ = 'checksum_dict.default'
- __mypyc_attrs__ = ('__dict__',)
- __orig_bases__ = (typing.DefaultDict[eth_typing.evm.ChecksumAddress, ~T], checksum_dict.base.ChecksumAddressDict[~T])
- __parameters__ = (~T,)
- default_factory
Factory for default value called by __missing__().
checksum_dict.exceptions module
- final exception checksum_dict.exceptions.KeyError[source]
Bases:
KeyError- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- __reduce__()
Helper for pickle.
- __setstate__(state, /)
- __str__()
Return str(self).
- add_note(note, /)
Add a note to the exception
- with_traceback(tb, /)
Set self.__traceback__ to tb and return self.
- __cause__
- __context__
- __dict__ = mappingproxy({'__module__': 'checksum_dict.exceptions', '__firstlineno__': 4, '__repr__': <function KeyError.__repr__>, '__static_attributes__': (), '__weakref__': <attribute '__weakref__' of 'KeyError' objects>, '__doc__': None, '__final__': True, '__annotations_cache__': {}})
- __final__ = True
- __firstlineno__ = 4
- __module__ = 'checksum_dict.exceptions'
- __static_attributes__ = ()
- __suppress_context__
- __traceback__
- __weakref__
list of weak references to the object
- args
checksum_dict.singleton module
- class checksum_dict.singleton.ChecksumAddressSingletonMeta[source]
-
A metaclass for creating singleton instances of addresses.
This metaclass ensures that each address has a single instance across the application. It uses a
ChecksumAddressDictto store instances and manages locks to ensure thread safety during instance creation.Note
This implementation uses a
cchecksum’s Cython implementation for checksumming to optimize performance over the standardeth_utils.to_checksum_address().Examples
>>> class MySingleton(metaclass=ChecksumAddressSingletonMeta): ... def __init__(self, address): ... self.address = address ... >>> instance1 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb') >>> instance2 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb') >>> assert instance1 is instance2
See also
ChecksumAddressDictfor the underlying dictionary implementation.
- __call__(address, *args, **kwargs)[source]
Create or retrieve a singleton instance for the given address.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to create or retrieve the singleton instance.
*args (Any) – Additional positional arguments for instance creation.
**kwargs (Any) – Additional keyword arguments for instance creation.
- Returns:
The singleton instance associated with the given address.
- Raises:
KeyError – If the address is not found in the cache.
- Return type:
T
Examples
>>> class MySingleton(metaclass=ChecksumAddressSingletonMeta): ... def __init__(self, address): ... self.address = address ... >>> instance = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- classmethod __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __delattr__(name, /)
Implement delattr(self, name).
- __delitem__(address)[source]
Delete the singleton instance for a given address from the cache.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to delete the instance.
- Raises:
KeyError – If the address is not found in the cache.
- Return type:
None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> del meta['0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb']
- __dir__()
Specialized __dir__ implementation for types.
- __getattribute__(name, /)
Return getattr(self, name).
- __getitem__(address)[source]
Get the singleton instance for address from the cache.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to retrieve the singleton instance.
- Returns:
The singleton instance associated with the given address.
- Raises:
KeyError – If the address is not found in the cache.
- Return type:
T
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> instance = meta['0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb']
- __init__(name, bases, namespace)[source]
Initialize the metaclass with a name, bases, and namespace.
- classmethod __init_subclass__()
Function to initialize subclasses.
- __instancecheck__(instance, /)
Check if an object is an instance.
- classmethod __new__(*args, **kwargs)
- __or__(value, /)
Return self|value.
- classmethod __prepare__(name, bases, /, **kwds)
Create the namespace for the class statement
- __repr__()
Return repr(self).
- __ror__(value, /)
Return value|self.
- __setattr__(name, value, /)
Implement setattr(self, name, value).
- __setitem__(address, item)[source]
Set the singleton instance for address in the cache.
You can use this if you need to implement non-standard init sequences.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to set the singleton instance.
item (T) – The instance to associate with the given address.
- Return type:
None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> meta['0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb'] = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- __sizeof__()
Return memory consumption of the type object.
- __subclasscheck__(subclass, /)
Check if a class is a subclass.
- __subclasses__()
Return a list of immediate subclasses.
- delete_instance(address)[source]
Delete the singleton instance for a given address, if it exists.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to delete the instance.
- Return type:
None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> meta.delete_instance('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- get_instance(address)[source]
Retrieve the singleton instance for a given address, if it exists.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to retrieve the instance.
- Returns:
The instance associated with the address, or None if not found.
- Return type:
T | None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> instance = meta.get_instance('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- mro()
Return a type’s method resolution order.
- __annotate__ = None
- __annotate_func__ = None
- __annotations__ = {'__instances': 'Final[ChecksumAddressDict[T]]', '__locks': 'Final[_LocksDict]', '__locks_lock': 'Final[threading.Lock]'}
- __annotations_cache__ = {'__instances': 'Final[ChecksumAddressDict[T]]', '__locks': 'Final[_LocksDict]', '__locks_lock': 'Final[threading.Lock]'}
- __bases__ = (<class 'type'>, <class 'typing.Generic'>)
- __basicsize__ = 936
- __dict__ = mappingproxy({'__module__': 'checksum_dict.singleton', '__firstlineno__': 13, '__doc__': "A metaclass for creating singleton instances of addresses.\n\nThis metaclass ensures that each address has a single instance across the application.\nIt uses a :class:`~checksum_dict.base.ChecksumAddressDict` to store instances and manages locks to ensure\nthread safety during instance creation.\n\nNote:\n This implementation uses a :mod:`cchecksum`'s Cython implementation for checksumming to optimize\n performance over the standard :func:`eth_utils.to_checksum_address`.\n\nExamples:\n >>> class MySingleton(metaclass=ChecksumAddressSingletonMeta):\n ... def __init__(self, address):\n ... self.address = address\n ...\n >>> instance1 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')\n >>> instance2 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')\n >>> assert instance1 is instance2\n\nSee Also:\n - :class:`ChecksumAddressDict` for the underlying dictionary implementation.\n", '__init__': <function ChecksumAddressSingletonMeta.__init__>, '__call__': <function ChecksumAddressSingletonMeta.__call__>, '__getitem__': <function ChecksumAddressSingletonMeta.__getitem__>, '__setitem__': <function ChecksumAddressSingletonMeta.__setitem__>, '__delitem__': <function ChecksumAddressSingletonMeta.__delitem__>, 'get_instance': <function ChecksumAddressSingletonMeta.get_instance>, 'delete_instance': <function ChecksumAddressSingletonMeta.delete_instance>, '_ChecksumAddressSingletonMeta__get_address_lock': <function ChecksumAddressSingletonMeta.__get_address_lock>, '_ChecksumAddressSingletonMeta__delete_address_lock': <function ChecksumAddressSingletonMeta.__delete_address_lock>, '__static_attributes__': ('__instances', '__locks', '__locks_lock'), '__orig_bases__': (<class 'type'>, typing.Generic[~T]), '__parameters__': (~T,), '__annotations_cache__': {'__instances': 'Final[ChecksumAddressDict[T]]', '__locks': 'Final[_LocksDict]', '__locks_lock': 'Final[threading.Lock]'}})
- __dictoffset__ = 264
- __firstlineno__ = 13
- __flags__ = 2155894272
- __itemsize__ = 40
- __module__ = 'checksum_dict.singleton'
- __mro__ = (<class 'checksum_dict.singleton.ChecksumAddressSingletonMeta'>, <class 'type'>, <class 'typing.Generic'>, <class 'object'>)
- __name__ = 'ChecksumAddressSingletonMeta'
- __orig_bases__ = (<class 'type'>, typing.Generic[~T])
- __parameters__ = (~T,)
- __qualname__ = 'ChecksumAddressSingletonMeta'
- __static_attributes__ = ('__instances', '__locks', '__locks_lock')
- __text_signature__ = None
- __type_params__ = ()
- __weakrefoffset__ = 368
Module contents
- exception checksum_dict.KeyError[source]
Bases:
KeyError- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- __reduce__()
Helper for pickle.
- __setstate__(state, /)
- __str__()
Return str(self).
- add_note(note, /)
Add a note to the exception
- with_traceback(tb, /)
Set self.__traceback__ to tb and return self.
- __annotations_cache__ = {}
- __cause__
- __context__
- __dict__ = mappingproxy({'__module__': 'checksum_dict.exceptions', '__firstlineno__': 4, '__repr__': <function KeyError.__repr__>, '__static_attributes__': (), '__weakref__': <attribute '__weakref__' of 'KeyError' objects>, '__doc__': None, '__final__': True, '__annotations_cache__': {}})
- __final__ = True
- __firstlineno__ = 4
- __module__ = 'checksum_dict.exceptions'
- __static_attributes__ = ()
- __suppress_context__
- __traceback__
- __weakref__
list of weak references to the object
- args
- class checksum_dict.ChecksumAddressDict
Bases:
dict[ChecksumAddress,T]- classmethod __class_getitem__(object, /)
See PEP 585
- __contains__(key, /)
True if the dictionary has the specified key, else False.
- __delitem__(key, /)
Delete self[key].
- __eq__(value, /)
Return self==value.
- __ge__(value, /)
Return self>=value.
- __getitem__(key, /)
Return self[key].
- __getstate__()
Helper for pickle.
- __gt__(value, /)
Return self>value.
- __init__(*args, **kwargs)
- __ior__(value, /)
Return self|=value.
- __iter__()
Implement iter(self).
- __le__(value, /)
Return self<=value.
- __len__()
Return len(self).
- __lt__(value, /)
Return self<value.
- __ne__(value, /)
Return self!=value.
- classmethod __new__(*args, **kwargs)
- __or__(value, /)
Return self|value.
- __repr__()
Return repr(self).
- __reversed__()
Return a reverse iterator over the dict keys.
- __ror__(value, /)
Return value|self.
- __setitem__(key, value, /)
Set self[key] to value.
- __setstate__(object, /)
- __sizeof__()
Return the size of the dict in memory, in bytes.
- clear()
Remove all items from the dict.
- copy()
Return a shallow copy of the dict.
- classmethod fromkeys(iterable, value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- __annotations_cache__ = {}
- __dict__ = mappingproxy({'__orig_bases__': (dict[eth_typing.evm.ChecksumAddress, ~T],), '__repr__': <slot wrapper '__repr__' of 'ChecksumAddressDict' objects>, '__init__': <slot wrapper '__init__' of 'ChecksumAddressDict' objects>, '__getitem__': <slot wrapper '__getitem__' of 'ChecksumAddressDict' objects>, '__setitem__': <slot wrapper '__setitem__' of 'ChecksumAddressDict' objects>, '__delitem__': <slot wrapper '__delitem__' of 'ChecksumAddressDict' objects>, '_getitem_nochecksum': <method '_getitem_nochecksum' of 'ChecksumAddressDict' objects>, '_setitem_nochecksum': <method '_setitem_nochecksum' of 'ChecksumAddressDict' objects>, '__setstate__': <method '__setstate__' of 'ChecksumAddressDict' objects>, '__getstate__': <method '__getstate__' of 'ChecksumAddressDict' objects>, '__dict__': <attribute '__dict__' of 'ChecksumAddressDict' objects>, '__doc__': '', '__module__': 'checksum_dict.base', '__mypyc_attrs__': ('__dict__',), '__annotations_cache__': {}})
- __hash__ = None
- __module__ = 'checksum_dict.base'
- __mypyc_attrs__ = ('__dict__',)
- __orig_bases__ = (dict[eth_typing.evm.ChecksumAddress, ~T],)
- class checksum_dict.ChecksumAddressSingletonMeta[source]
-
A metaclass for creating singleton instances of addresses.
This metaclass ensures that each address has a single instance across the application. It uses a
ChecksumAddressDictto store instances and manages locks to ensure thread safety during instance creation.Note
This implementation uses a
cchecksum’s Cython implementation for checksumming to optimize performance over the standardeth_utils.to_checksum_address().Examples
>>> class MySingleton(metaclass=ChecksumAddressSingletonMeta): ... def __init__(self, address): ... self.address = address ... >>> instance1 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb') >>> instance2 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb') >>> assert instance1 is instance2
See also
ChecksumAddressDictfor the underlying dictionary implementation.
- __call__(address, *args, **kwargs)[source]
Create or retrieve a singleton instance for the given address.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to create or retrieve the singleton instance.
*args (Any) – Additional positional arguments for instance creation.
**kwargs (Any) – Additional keyword arguments for instance creation.
- Returns:
The singleton instance associated with the given address.
- Raises:
KeyError – If the address is not found in the cache.
- Return type:
T
Examples
>>> class MySingleton(metaclass=ChecksumAddressSingletonMeta): ... def __init__(self, address): ... self.address = address ... >>> instance = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- classmethod __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __delattr__(name, /)
Implement delattr(self, name).
- __delitem__(address)[source]
Delete the singleton instance for a given address from the cache.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to delete the instance.
- Raises:
KeyError – If the address is not found in the cache.
- Return type:
None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> del meta['0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb']
- __dir__()
Specialized __dir__ implementation for types.
- __getattribute__(name, /)
Return getattr(self, name).
- __getitem__(address)[source]
Get the singleton instance for address from the cache.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to retrieve the singleton instance.
- Returns:
The singleton instance associated with the given address.
- Raises:
KeyError – If the address is not found in the cache.
- Return type:
T
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> instance = meta['0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb']
- __init__(name, bases, namespace)[source]
Initialize the metaclass with a name, bases, and namespace.
- classmethod __init_subclass__()
Function to initialize subclasses.
- __instancecheck__(instance, /)
Check if an object is an instance.
- classmethod __new__(*args, **kwargs)
- __or__(value, /)
Return self|value.
- classmethod __prepare__(name, bases, /, **kwds)
Create the namespace for the class statement
- __repr__()
Return repr(self).
- __ror__(value, /)
Return value|self.
- __setattr__(name, value, /)
Implement setattr(self, name, value).
- __setitem__(address, item)[source]
Set the singleton instance for address in the cache.
You can use this if you need to implement non-standard init sequences.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to set the singleton instance.
item (T) – The instance to associate with the given address.
- Return type:
None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> meta['0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb'] = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- __sizeof__()
Return memory consumption of the type object.
- __subclasscheck__(subclass, /)
Check if a class is a subclass.
- __subclasses__()
Return a list of immediate subclasses.
- delete_instance(address)[source]
Delete the singleton instance for a given address, if it exists.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to delete the instance.
- Return type:
None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> meta.delete_instance('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- get_instance(address)[source]
Retrieve the singleton instance for a given address, if it exists.
- Parameters:
address (Address | HexAddress | ChecksumAddress | Contract | ERC20) – The address for which to retrieve the instance.
- Returns:
The instance associated with the address, or None if not found.
- Return type:
T | None
Examples
>>> meta = ChecksumAddressSingletonMeta('MySingleton', (), {}) >>> instance = meta.get_instance('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')
- mro()
Return a type’s method resolution order.
- __annotate__ = None
- __annotate_func__ = None
- __annotations__ = {'__instances': 'Final[ChecksumAddressDict[T]]', '__locks': 'Final[_LocksDict]', '__locks_lock': 'Final[threading.Lock]'}
- __annotations_cache__ = {'__instances': 'Final[ChecksumAddressDict[T]]', '__locks': 'Final[_LocksDict]', '__locks_lock': 'Final[threading.Lock]'}
- __bases__ = (<class 'type'>, <class 'typing.Generic'>)
- __basicsize__ = 936
- __dict__ = mappingproxy({'__module__': 'checksum_dict.singleton', '__firstlineno__': 13, '__doc__': "A metaclass for creating singleton instances of addresses.\n\nThis metaclass ensures that each address has a single instance across the application.\nIt uses a :class:`~checksum_dict.base.ChecksumAddressDict` to store instances and manages locks to ensure\nthread safety during instance creation.\n\nNote:\n This implementation uses a :mod:`cchecksum`'s Cython implementation for checksumming to optimize\n performance over the standard :func:`eth_utils.to_checksum_address`.\n\nExamples:\n >>> class MySingleton(metaclass=ChecksumAddressSingletonMeta):\n ... def __init__(self, address):\n ... self.address = address\n ...\n >>> instance1 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')\n >>> instance2 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb')\n >>> assert instance1 is instance2\n\nSee Also:\n - :class:`ChecksumAddressDict` for the underlying dictionary implementation.\n", '__init__': <function ChecksumAddressSingletonMeta.__init__>, '__call__': <function ChecksumAddressSingletonMeta.__call__>, '__getitem__': <function ChecksumAddressSingletonMeta.__getitem__>, '__setitem__': <function ChecksumAddressSingletonMeta.__setitem__>, '__delitem__': <function ChecksumAddressSingletonMeta.__delitem__>, 'get_instance': <function ChecksumAddressSingletonMeta.get_instance>, 'delete_instance': <function ChecksumAddressSingletonMeta.delete_instance>, '_ChecksumAddressSingletonMeta__get_address_lock': <function ChecksumAddressSingletonMeta.__get_address_lock>, '_ChecksumAddressSingletonMeta__delete_address_lock': <function ChecksumAddressSingletonMeta.__delete_address_lock>, '__static_attributes__': ('__instances', '__locks', '__locks_lock'), '__orig_bases__': (<class 'type'>, typing.Generic[~T]), '__parameters__': (~T,), '__annotations_cache__': {'__instances': 'Final[ChecksumAddressDict[T]]', '__locks': 'Final[_LocksDict]', '__locks_lock': 'Final[threading.Lock]'}})
- __dictoffset__ = 264
- __firstlineno__ = 13
- __flags__ = 2155894272
- __itemsize__ = 40
- __module__ = 'checksum_dict.singleton'
- __mro__ = (<class 'checksum_dict.singleton.ChecksumAddressSingletonMeta'>, <class 'type'>, <class 'typing.Generic'>, <class 'object'>)
- __name__ = 'ChecksumAddressSingletonMeta'
- __orig_bases__ = (<class 'type'>, typing.Generic[~T])
- __parameters__ = (~T,)
- __qualname__ = 'ChecksumAddressSingletonMeta'
- __static_attributes__ = ('__instances', '__locks', '__locks_lock')
- __text_signature__ = None
- __type_params__ = ()
- __weakrefoffset__ = 368
- class checksum_dict.DefaultChecksumDict
Bases:
DefaultDict[ChecksumAddress,T],ChecksumAddressDict[T]- classmethod __class_getitem__(object, /)
See PEP 585
- __contains__(key, /)
True if the dictionary has the specified key, else False.
- __copy__()
D.copy() -> a shallow copy of D.
- __delitem__(key, /)
Delete self[key].
- __eq__(value, /)
Return self==value.
- __ge__(value, /)
Return self>=value.
- __getattribute__(name, /)
Return getattr(self, name).
- __getitem__(key, /)
Return self[key].
- __getstate__()
Helper for pickle.
- __gt__(value, /)
Return self>value.
- __init__(*args, **kwargs)
- classmethod __init_subclass__()
Function to initialize subclasses.
- __ior__(value, /)
Return self|=value.
- __iter__()
Implement iter(self).
- __le__(value, /)
Return self<=value.
- __len__()
Return len(self).
- __lt__(value, /)
Return self<value.
- __missing__(object, /)
__missing__(key) # Called by __getitem__ for missing key; pseudo-code: if self.default_factory is None: raise KeyError((key,)) self[key] = value = self.default_factory() return value
- __ne__(value, /)
Return self!=value.
- classmethod __new__(*args, **kwargs)
- __or__(value, /)
Return self|value.
- __reduce__()
Return state information for pickling.
- __repr__()
Return repr(self).
- __reversed__()
Return a reverse iterator over the dict keys.
- __ror__(value, /)
Return value|self.
- __setitem__(key, value, /)
Set self[key] to value.
- __setstate__(object, /)
- __sizeof__()
Return the size of the dict in memory, in bytes.
- clear()
Remove all items from the dict.
- copy() a shallow copy of D.
- classmethod fromkeys(iterable, value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- __annotate_func__ = None
- __annotations_cache__ = {}
- __dict__ = mappingproxy({'__orig_bases__': (typing.DefaultDict[eth_typing.evm.ChecksumAddress, ~T], checksum_dict.base.ChecksumAddressDict[~T]), '__init__': <slot wrapper '__init__' of 'DefaultChecksumDict' objects>, '_getitem_nochecksum': <method '_getitem_nochecksum' of 'DefaultChecksumDict' objects>, '__setstate__': <method '__setstate__' of 'DefaultChecksumDict' objects>, '__getstate__': <method '__getstate__' of 'DefaultChecksumDict' objects>, '__dict__': <attribute '__dict__' of 'DefaultChecksumDict' objects>, '__doc__': '', '__module__': 'checksum_dict.default', '__parameters__': (~T,), '__mypyc_attrs__': ('__dict__',), '__annotations_cache__': {}})
- __hash__ = None
- __module__ = 'checksum_dict.default'
- __mypyc_attrs__ = ('__dict__',)
- __orig_bases__ = (typing.DefaultDict[eth_typing.evm.ChecksumAddress, ~T], checksum_dict.base.ChecksumAddressDict[~T])
- __parameters__ = (~T,)
- default_factory
Factory for default value called by __missing__().