schrodinger.utils.scollections module¶
-
class
schrodinger.utils.scollections.
IdentityDict
¶ Bases:
collections.abc.MutableMapping
,dict
An identity dict is a dictionary that uses the id of an object as the key instead of the hash. This means that two objects that compare equal but are different instances will be stored separately since id(obj1) != id(obj2).
NOTE: Using this dict with pythons builtin immutable datatypes is /strongly/ discouraged.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
has_key
(obj)¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
clear
() → None. Remove all items from D.¶
-
-
class
schrodinger.utils.scollections.
DefaultFactoryDictMixin
(factory_func, *args, **kwargs)¶ Bases:
object
A mixin to use with
dict
’s that allows the dict to use a factory function similar todefaultdict
. The key distinction here is that the factory function will be passed the key itself instead of called without any arguments.Note
Despite the name, this mixin works with classes as well. When passed a class, the constructor will be called and passed the keys.
Warning
This mixin will not work with factory functions that expect only one tuple as an argument. This is due to the way
__getitem__
packages up all keys in a single call into one tuple.
-
class
schrodinger.utils.scollections.
DefaultFactoryDict
(factory_func, *args, **kwargs)¶ Bases:
schrodinger.utils.scollections.DefaultFactoryDictMixin
,dict
A basic
dict
using theDefaultFactoryDictMixin
. This is separated from the mixin to allow otherdict
subclasses to easily subclassDefaultFactoryDictMixin
.- Example usage::
- stringified_objs = DefaultFactoryDict(str) assert 1 not in stringified_objs print(stringified_objs[1]) # ‘1’