Skip to content

bpo-46071: Improve graphlib documentation & reverse edge direction. #30102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

bpo-46071: Improve graphlib documentation & reverse edge direction. #30102

wants to merge 2 commits into from

Conversation

ctrl-z-9000-times
Copy link

@ctrl-z-9000-times ctrl-z-9000-times commented Dec 14, 2021

This reverses the direction of the edges, and alters the definition of
topological sorting accordingly. This should make the interface much
more intuitive to use.

I also rephrased most of the text for clarity.

No functional changes.

https://bugs.python.org/issue46071

This reverses the direction of the edges, and alters the definition of
topological sorting accordingly. This should make the interface much
more intuitive to use.

I also rephrased most of the text for clarity.

No functional changes.
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@ctrl-z-9000-times

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
I don't think that wild changes in already used terms make sense.
The predecessor node is incoming, not outgoing.
It cannot be changed just in docs without internal logic updating (conditions when a node becomes 'ready').
The logic update, in turn, is not backward compatible.

Lib/graphlib.py Outdated
@@ -56,40 +57,40 @@ def _get_nodeinfo(self, node):
self._node2info[node] = result = _NodeInfo(node)
return result

def add(self, node, *predecessors):
"""Add a new node and its predecessors to the graph.
def add(self, start_node, *end_nodes):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, the change is not backward compatible.
The current module allows keyword notation: `topo.add(node='a', 'b', 'c', 'd')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I reverted the name from start_node back to node.

I have made the requested changes; please review again

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ctrl-z-9000-times
Copy link
Author

I think you misunderstand:

  1. I reserved the direction of the edges and also reversed the direction of the final sorted output, and those two reversals cancel each other out; so there are no logic changes needed.

  2. I did not change the meaning of the word predecessors; I removed that word entirely.
    Instead I rewrote it to explicitly state the edge direction "from node X to node Y".

  3. "The predecessor node is incoming, not outgoing."

According to the original docs it's actually the other way around:

https://docs.python.org/3/library/graphlib.html
If the optional graph argument is provided it must be a dictionary representing a directed acyclic graph where the keys are nodes and the values are iterables of all predecessors of that node in the graph (the nodes that have edges that point to the value in the key).

@ctrl-z-9000-times
Copy link
Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@asvetlov: please review the changes made to this pull request.

@ctrl-z-9000-times
Copy link
Author

Actually, I think I'd like to add a few more sentences.

  • I missed the word "successor" in method done(). I'm going to rephrase that using the terms "tasks" & "dependencies".
  • The optional graph argument must explicitly state how to use it to store tasks & their dependencies, especially since I removed all of the "predecessor / successor" wording.
  • The first paragraph could be a little more clear about the purpose of this class? It introduces task & dependency resolution as an example but, actually, a lot of what this class does is geared towards this use case. And some of the documentation does not make sense outside of the context of dependency resolution.
    • Maybe it could say something like "This class specializes in managing dependency resolution among tasks to be performed"

Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view, 'predecessor' is for 'incoming edge', not for 'outgoing'

@ctrl-z-9000-times
Copy link
Author

I split this into two PR's:

#30223 - Reverses the edge direction

#30269 - General cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants