Andrew Barnert said on Mon, Jan 05, 2015 at 01:09:37PM +0100:
On Jan 5, 2015, at 12:20, Alexis Lee firstname.lastname@example.org wrote: You're trying to find out if dst is an ancestor of src (the option of taking a list of pairs, despite being documented, seems to be there only for internal use by recursive calls) and, if so, how long the path is between them.
(moved for clarity)
When would it ever be interesting?
The usecase is here (comments at line 861, also see 866-894): https://review.openstack.org/#/c/142835/5/nova/api/openstack/compute/servers...
IE I receive a NeutronException of some specialised type; based on that there are multiple Nova exceptions I might want to throw. I would use getclassdistance (or rather, your walker) to sort those and throw the first, most-specific exception. EG I might be considering throwing either HTTPConflict or HTTPBadRequest, but the former is-a latter, hence it's more specific and the one which should be thrown.
Never used abc; happy to enhance if the usecase is useful.
Yes. Although thinking about it, I actually want the longest path to count. Curses. This behaviour should be a toggle parameter.
Yes. MRO distance is trivial to obtain from __mro__.
Also, it seems like it would be simpler to just create a general inheritance-BFS-walker function that yields each base as it goes, which would allow you to write this function as a one-liner.
Yes, that's fair. I'll wait for some more feedback on whether such a thing would be useful in the stdlib at all before writing that.
I also don't get why you're using recursion rather than a loop here,
Just how I think.
Nova Engineer, HP Cloud. AKA lealexis, lxsli.