Exposing the ABC registration graph (was Re: Json object-level serializer)

On Sat, Jul 31, 2010 at 10:12 PM, Antoine Pitrou <solipsis@pitrou.net> wrote:
There's a related problem here that ties into one of the complaints I have with pkgutil.simplegeneric: because that decorator relies on MRO traversal in order to obtain a reasonably efficient implementation, it completely ignores any ABC registrations. That's fairly suboptimal, since a comparable chain of "isinstance()" checks *will* respect ABC registrations (it's just horrendously slow and doesn't scale, since the worst-case number of checks increases linearly with the number of branches in the if-elif chain). So I think the idea of query methods in the abc module is a good way to go. It allows the Python implementation freedom in choosing whether to have separate type registries stored on the ABCs themselves, or instead have global registries stored in the abc module. In particular, it allows the interpreter to cache the transitive closure of the ABC graph, such that an application can ask for the set of all objects that implement a given ABC, as well as the set of all ABCs that a given object implements. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (1)
-
Nick Coghlan