This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Arfrever, barry, eli.bendersky, eric.araujo, eric.smith, ethan.furman, georg.brandl, jaraco, mark.dickinson, mrabarnett, pitrou, r.david.murray, rhettinger, sbt, serhiy.storchaka, theller, tim.peters, vstinner
Date 2013-12-13.08:12:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1386922345.4.0.596950588157.issue18986@psf.upfronthosting.co.za>
In-reply-to
Content
> Mark, what was the use case you found?

It's essentially an IdentityDict, though I've found other more specific transforms useful.

I was writing a tool to find reference cycles between Python objects (we have a customer application that's working in a multithreaded COM environment and has to ensure that COM objects are released on the same types of threads they were created on, so we have to be careful about cyclic garbage and delayed garbage collection).

The graph of Python objects (class 'ObjectGraph') is modelled as a fairly standard directed graph (set of vertices, set of edges, two dictionaries mapping each edge to its head and tail), but of course for this application the dict and set have to be based on object identity rather than normal equality.  Using a TransformDict (and an IdentitySet) lets me write the standard graph algorithms (e.g., for finding strongly connected components) in a natural way, leaving it to the TransformDict and IdentitySet to do the necessary id() conversions under the hood.)

I also have a similar AnnotatedGraph object (a sort of offline version of the ObjectGraph), where the edges and vertices carry additional information and it's convenient to be able to use a lightweight ID rather than an entire vertex or edge as a dictionary key.  Again, using a TransformDict lets one hide the details and present the graph manipulation code readably and naturally.

Some code here, if you're interested:

https://github.com/mdickinson/refcycle/blob/refactor/refcycle/object_graph.py

Caveat: it's work in progress.
History
Date User Action Args
2013-12-13 08:12:25mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, barry, theller, georg.brandl, rhettinger, jaraco, pitrou, vstinner, eric.smith, eric.araujo, mrabarnett, Arfrever, r.david.murray, eli.bendersky, ethan.furman, sbt, serhiy.storchaka
2013-12-13 08:12:25mark.dickinsonsetmessageid: <1386922345.4.0.596950588157.issue18986@psf.upfronthosting.co.za>
2013-12-13 08:12:25mark.dickinsonlinkissue18986 messages
2013-12-13 08:12:24mark.dickinsoncreate