-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[Do not merge] Adding crossrefs to standard library #7624
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
Conversation
Open points:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think None
should be replaced with a link. It has the same kind of status as True
and False
, which you don't change.
Also perhaps not every mention of Any
needs to be linked? This gets kind of busy, and there are a lot of occurrences of it.
Also, I merged your first PR, so this one now has conflicts to resolve. (Probably just remove the first commit.) |
@gvanrossum first of all, thank you for reviewing the other PR! I'm not happy with this first iteration myself - played too much with
Also, I have discovered |
77124e3
to
c09c276
Compare
Thanks, those rules seem reasonable, except I would personally categorize |
e3d146c
to
4618e9e
Compare
Signed-off-by: Oleg Höfling <[email protected]>
4618e9e
to
7e601c0
Compare
I think I have it ready for a review now; sadly, these are still a lot of changes. However, all refs are valid as Sphinx doesn't emit any warnings when building docs. To verify locally, install Sphinx via As the overall diff is enormously big, it will probably take a lot of time to verify in one go - I will gladly break the changes up into multiple PRs if you wish (e.g. one PR per document). I have also discovered and fixed minor issues like using markdown instead of ReST or syntax errors in code examples. This adds up to the total diffs, sadly. I have decided not to reference Last but not least: refs to py38 featuresI have also referenced the new features in Python 3.8 (
Is this too soon / should this be rather done in a separate PR? |
Additional ideas: doctest code examples?In our company's docs, we require that each example is inside in a API docs?I saw |
Here's an example documentation showing how the rendered API could look like, with a minimal subset of the codebase made available. |
…ax in failing examples Signed-off-by: Oleg Höfling <[email protected]>
Before I go review this in detail, let me suggest that you try to focus on a single issue per PR. If you have additional ideas on which you'd like to receive feedback (e.g. API docs) please open a new issue. If you have fixes that are unrelated to the core change here (making things link to the Python docs), submit them as a separate PR (we can land those immediately). I would also skip linking to Python 3.8 -- even after that's released, most people will not immediately upgrade, so Finally, you have a few links (e.g. |
Another suggestion: don't be too clever with not linking to the docs more than once per page / section / file / whatever. The non-link markup actually looks more hideous (red) than the link markup (black bold). And if you look through Python's own docs, in general when something is linked, there's no fear to link to it multiple times. (Example: in
I haven't checked if the Python docs are consistent in this (it's all done manually and I'm sure different authors use slightly different conventions) but I'd say stick to the KISS principle (Keep It Simple, Stupid), which in this case I interpret as "for a particular term, either never link or always link". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, this is too much to review in one go. Would it make sense to split it up in, say, 5-6 PRs, for groups of 5-6 files each?
That enables this to work: | ||
easier. :py:func:`attr.ib` and :py:class:`attr.Factory` actually | ||
return objects, but the annotation says these return the types that | ||
they expect to be assigned to. That enables this to work: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diff chunks like this one look worse than they are because the paragraph was reformatted. We don't particularly care about line lengths in the doc sources. Perhaps the diff would be simpler if you just let the lines become longer, and kept the line breaks where they were? (GitHub has a nice feature where it uses two different shares of red and green to indicate text that was just moved vs. text that was actually changed, but reflowing a paragraph is considered to be an actual change. :-( )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the job a lot easier, knowing this!
As an experimental mypy extension, you can specify | ||
:py:data:`~typing.Callable` types that support keyword arguments, | ||
optional arguments, and more. When you specify the arguments of a | ||
``Callable``, you can choose to supply just the type of a nameless |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an example of the KISS principle I mentioned, this second occurrence of Callable
could easily be linked as well, even though it's in the same paragraph as the first.
@@ -22,19 +22,22 @@ Type Description | |||
``Any`` dynamically typed value with an arbitrary type | |||
====================== =============================== | |||
|
|||
The type ``Any`` and type constructors such as ``List``, ``Dict``, | |||
``Iterable`` and ``Sequence`` are defined in the ``typing`` module. | |||
The type :py:data:`~typing.Any` and type constructors such as :py:class:`~typing.List`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking that all the types mentioned here are just too common to bother linking to their docs. I would only link the typing
module itself.
Another idea: just above here is a table showing the most common built-in types. Maybe the items in the table should be linked instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about linking the table items instead, but the classes listed contain types, e.g. Tuple[int, int]
. The typing
module docs do not link those, e.g. Optional
docs. I guess it counts as an example, which are not linked in the stdlib docs.
@@ -34,8 +34,8 @@ quite understand what is going on. | |||
assert isinstance(o, int) | |||
print(o + 5) # OK: type of 'o' is 'int' here | |||
|
|||
You don't need a cast for expressions with type ``Any``, or when | |||
assigning to a variable with type ``Any``, as was explained earlier. | |||
You don't need a cast for expressions with type :py:data:`~typing.Any`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, Any
should probably not be linked. It's just too common. Also, the explanation of this type in the Python docs is rather lame. If anything, it should probably link to an explanation of the concept in the mypy docs (if there is one), or perhaps in PEP 483.
@@ -24,8 +25,8 @@ initialized within the class. Mypy infers the types of attributes: | |||
a.y = 3 # Error: 'A' has no attribute 'y' | |||
|
|||
This is a bit like each class having an implicitly defined | |||
``__slots__`` attribute. This is only enforced during type | |||
checking and not when your program is running. | |||
:py:data:`__slots__ <object.__slots__>` attribute. This is only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example of one where I do think the link is useful.
Thank you for guiding me through this - I have never contributed anything more significant than a bugfix, so I'm still learning to find the right balance between "this change should be included no matter what" and "any sane person should be able to review it in the end". I suggest to keep this PR open while I land more related PRs and once I verified each change has found its place, I will simply close this one (and open new issues for proposals that I'm not sure whether or how to solve). |
Closing this since the changes were reworked and landed in linked PRs. |
This is the second part of adding referencing to
mypy
docs (first part in #7623, this one is based on the first part). Replaced verbatim texts with crossrefs to standard library where applicable. Example: a passagebecomes
where each "bold verbatim" block references to the relevant spot in the standard library. IMO this has several advantages:
mypy
docs, one doesn't need to keep a separate tab withtyping
docs opened, each term is immediately available for lookup.SupportsRound
and immediately get the hint - aha, this is part of the stdlib,typing
module, can read it up later. Otherwise, especially an unexperienced reader will first have to googleSupportsRound
in separate tab.