[issue47145] Improve graphlib.TopologicalSort by removing the prepare step

Tim Peters report at bugs.python.org
Wed Mar 30 20:02:25 EDT 2022


Tim Peters <tim at python.org> added the comment:

Various kinds of tasks:

- "Power switch must be on." Needs to done the first time. _May_ need to be done again later (if some later task turns the power off again). Can be done any number of times without harm (beyond the expense of checking), so long as the switch is on.

- "Ensure gas tank is full." Probably needs to be done anew for every new added task that depends on it.

- "Remove outermost layer of skin." Probably shouldn't be done more than once ;-)

- "Flip Najdorf switch." Who knows? Doing it a second time - or failing to do it a second time - may be necessary, harmless, or deadly.

I'd rather not bother with any of this dicey guessing. While some dynamism may be attractive, what it all "should mean" appears to be a rat's nest, and depends on domain knowledge graphlib can't possibly have.

I doubt there is a compelling default. As is, two tasks are considered to be "the same" task if and only if they compare equal, so that's the least _surprising_ default for tasks added later. "Remove outermost layer of skin"

"Two tasks that compare equal may or may not be considered the same task, depending on the execution history at the time the question is posed" is at best expedient, at worst disastrous.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47145>
_______________________________________


More information about the Python-bugs-list mailing list