class MappedCollection(dict):
A basic dictionary-based collection class.
Extends dict with the minimal bag semantics that collection classes require. set and remove are implemented in terms of a keying function: any callable that takes an object and returns an object for use as a dictionary key.
Method | __init__ |
Create a new collection with keying provided by keyfunc. |
Method | remove |
Remove an item by value, consulting the keyfunc for the key. |
Method | set |
Add an item by value, consulting the keyfunc for the key. |
Instance Variable | keyfunc |
Undocumented |
Create a new collection with keying provided by keyfunc.
keyfunc may be any callable that takes an object and returns an object for use as a dictionary key.
The keyfunc will be called every time the ORM needs to add a member by value-only (such as when loading instances from the database) or remove a member. The usual cautions about dictionary keying apply- keyfunc(object) should return the same output for the life of the collection. Keying based on mutable properties can result in unreachable instances "lost" in the collection.