Skip to content

bpo-46204: graphlib documentation: general improvements#30269

Closed
ctrl-z-9000-times wants to merge 1 commit intopython:mainfrom
ctrl-z-9000-times:graphlib-cleanup-docs
Closed

bpo-46204: graphlib documentation: general improvements#30269
ctrl-z-9000-times wants to merge 1 commit intopython:mainfrom
ctrl-z-9000-times:graphlib-cleanup-docs

Conversation

@ctrl-z-9000-times
Copy link

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

This PR cleans up the documentation for the graphlib module.

I rephrased for grammar and clarity but I did not change any of the semantics.

https://bugs.python.org/issue46204

@ctrl-z-9000-times ctrl-z-9000-times changed the title Improve graphlib's documentation. graphlib documentation: general improvements Dec 26, 2021
@AlexWaygood AlexWaygood added docs Documentation in the Doc dir skip news labels Dec 26, 2021
@AlexWaygood
Copy link
Member

I have added the skip-news label, since this is a docs-related PR, but I think this should be linked to a BPO issue, since there are some fairly substantial changes being proposed in this PR 🙂

@ctrl-z-9000-times ctrl-z-9000-times changed the title graphlib documentation: general improvements bpo-46204: graphlib documentation: general improvements Dec 30, 2021
@ctrl-z-9000-times
Copy link
Author

Ok, I opened a BPO issue for this PR.

Copy link
Member

@merwok merwok 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 your efforts to improve the docs! I have added some remarks and questions, and will also add a general question on the bug report.

Raises :exc:`ValueError` if called without calling
:meth:`~TopologicalSorter.prepare` previously.
Raises :exc:`ValueError` if this method is called before
:meth:`~TopologicalSorter.prepare`.
Copy link
Member

Choose a reason for hiding this comment

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

The previous text seems clear to me.

there are still nodes ready to be returned by
:meth:`~TopologicalSorter.get_ready` or there are nodes which were
returned by :meth:`~TopologicalSorter.get_ready` and which have not yet
been marked as :meth:`~TopologicalSorter.done`.
Copy link
Member

Choose a reason for hiding this comment

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

What is the problem with displaying the full name for these methods? It makes it clear that we’re talking about methods not functions for example.

Copy link
Author

Choose a reason for hiding this comment

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

It's too verbose. The phrase TopologicalSorter.get_ready() appears twice in the sentence.
IMO it should be obvious to the users that get_ready and done are methods, especially since they're clickable links.

before vertex v in the ordering. For instance, the vertices of the graph may
A topological order is a linear ordering of the nodes in a graph such that
for every directed edge u -> v from node u to node v, node u comes
before node v in the ordering. For instance, the nodes of the graph may
Copy link
Member

Choose a reason for hiding this comment

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

This is a substantial change that should be reviewed by the original author of the module and/or doc.

Copy link
Author

Choose a reason for hiding this comment

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

In this context, nodes and vertices are synonyms.
The word "node" is used everywhere else in the document except for this sentence.

ordering is possible if and only if the graph has no directed cycles, that
is, if it is a directed acyclic graph.
ordering is possible if and only if the graph is a directed acyclic graph,
that is, if there are no circular dependencies among the tasks to be performed.
Copy link
Member

Choose a reason for hiding this comment

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

I feel that tasks to be performed is one specific application of graphs, but not a generic term enough to fit in this doc.

Copy link
Author

Choose a reason for hiding this comment

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

If only that were true...
Alas it is clearly stated that the primary purpose of this class is to do task dependency resolution.

The class is designed to easily support parallel processing of the nodes as they become ready.


Raises :exc:`CycleError` if any cycles are detected,
but :meth:`~TopologicalSorter.get_ready` can still be used to obtain as
many nodes as possible until cycles block more progress.
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this change moves lines around without improving the substance.

.. method:: static_order()

Returns an iterator object which will iterate over nodes in a topological
Returns an iterator object which iterates over nodes in a topological
Copy link
Member

Choose a reason for hiding this comment

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

What error is being fixed here?



If any cycle is detected, :exc:`CycleError` will be raised.
Raises :exc:`CycleError` if any cycles are detected.
Copy link
Member

Choose a reason for hiding this comment

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

Why change this?

Copy link
Author

Choose a reason for hiding this comment

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

For consistency with the rest of pythons docs.
The error messages are usually written in the format:
Raises MyError if my-problem is encountered.

Also, I changed it to use the active voice instead of the passive voice.

Copy link
Member

Choose a reason for hiding this comment

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

I don’t think the original phrasing was incorrect or misleading or problematic in any way.
The Python codebase is old and made by many contributors. Not everything is fully consistent, and that is not a goal.

Copy link
Author

Choose a reason for hiding this comment

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

Yea its correct, but its still poorly written.

The current phrasing puts the most important word "raises" at the end of the sentence.
A reader who is skimming through the page is going to have to read all the way to the end of the sentence to see what the verb is.

The new phrasing starts with the word "Raises" so that before you've even read the sentence, you already know what topic its going to describe.
The new phrase is shorter and easier to comprehend.


def done(self, *nodes):
"""Marks a set of nodes returned by "get_ready" as processed.
"""Marks a set of nodes returned by "get_ready()" as processed.
Copy link
Member

Choose a reason for hiding this comment

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

I notice that this docstring (and some others) do not follow the common dosctring convention that verbs should be imperative (Mark), not indicative. Would you mind changing them?

number of nodes marked "done" is less than the number that have been returned
by "get_ready".
Progress can be made if cycles do not block the resolution and either
there are still nodes ready to be returned by "get_ready()" or there
Copy link
Member

Choose a reason for hiding this comment

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

Developers spend a lot of time looking at history, to find who changed some line when and for what reason.
Preserving the usefulness of that history is more important that strict line lengths, so here for example I would not rewrap the lines.

been marked as "done()".

Raises ValueError if called without calling "prepare" previously.
Raises ValueError if called before "prepare()".
Copy link
Member

Choose a reason for hiding this comment

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

This is personal, but I don’t like adding parentheses to all function names. It is clear enough that these are function (or method) names, and the parens suggest that they can be called without params, which is often not true. I don’t think there is a strong consensus about this for docstrings, so in this case I would preserve the existing style. (CPython does not value style uniformity over other things.)

@ctrl-z-9000-times
Copy link
Author

I think what I'd like to do with this PR is to split it further into many many more PRs.
That way when we debate the wording of one sentence, it does not block changes to other sentences.
Also, that way I can avoid having to open bugs report to justify each of these minor changes.


I would really appreciate if someone could comment on PR #30223 which unlike all of these changes is actually important.

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants