-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
gh-138307: Update the Ellipsis documentation #138306
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
This comment was marked as resolved.
This comment was marked as resolved.
Doc/library/stdtypes.rst
Outdated
special operations. There is exactly one ellipsis object, named | ||
:const:`Ellipsis` (a built-in name). ``type(Ellipsis)()`` produces the | ||
:const:`Ellipsis` singleton. | ||
|
||
It is written as ``Ellipsis`` or ``...``. | ||
|
||
For instance, at the standard library and its documentation, ``Ellipsis`` can | ||
appears in :ref:`pretty printers <prettyprinter-objects>`, |
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 gets awkward: the use in pretty printing is three dots, but it's not an Ellipsis object. It's a typographic convention for omitted content (which is why Python uses three dots for this).
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'll fix it.
Do you think we should add this third type to the glossary?
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.
Likewise recursive_repr uses ...
but it's not the Ellipsis
form of ...
.
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.
What about doctest.ELLIPIS? Now, I'm thinking it is three dots, not the Ellipsis object.
Co-authored-by: Stan Ulbrych <[email protected]>
Co-authored-by: Éric <[email protected]>
Co-authored-by: Éric <[email protected]>
Co-authored-by: Éric <[email protected]>
Doc/library/stdtypes.rst
Outdated
special operations. There is exactly one ellipsis object, named | ||
:const:`Ellipsis` (a built-in name). ``type(Ellipsis)()`` produces the | ||
:const:`Ellipsis` singleton. | ||
|
||
It is written as ``Ellipsis`` or ``...``. | ||
|
||
For instance, in the standard library and its documentation, ``Ellipsis`` can | ||
appears in | ||
:const:`documentation tests <doctest.ELLIPSIS>`, |
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.
doctest.ELLIPSIS
is not an Ellipsis object. It's yet another instance of using three dots to mean "something is missing here." In a doctest, ...
matches any text, like .*
in a regex.
BTW, another use of three dots is the secondary REPL prompt:
>>> (
...
We can list out these "faux Ellipses" (not in those words) as a way of helping people who end up here because they were trying to figure out what something means.
I would structure it something like this:
In typical use, ``...`` as an Ellipsis appears in a few different places:
- In type annotations for :ref:`Callable arguments <annotating-callables>` or `tuple elements <find-the-reference>`
- As the body of a function instead of a :ref:`pass statement <tut-pass>`
- In third-party libraries, such as Numpy's slicing and striding <https://numpy.org/doc/stable/user/basics.indexing.html#slicing-and-striding>`_
Python also uses three dots in ways that are not Ellipsis objects:
- Doctest's :const:`doctest.ELLIPSIS`, as a pattern for missing content
- As the interactive prompt for "please finish your statement"
Lastly, the Python documentation often uses three dots in conventional English usage to mean omitted content, even in code examples that also use them as an Ellipsis.
Doc/library/constants.rst
Outdated
The same as the ellipsis literal "``...``", an object frequently used as a | ||
placeholder for another value. Assignment to ``Ellipsis`` is possible, but |
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'm not sure "a placeholder for another value" is a good summary. I don't think it describes many of the typing use cases, for one.
Maybe "to indicate that something is omitted"?
Doc/library/stdtypes.rst
Outdated
For instance, in the standard library and its documentation, ``Ellipsis`` can | ||
appears in | ||
:const:`documentation tests <doctest.ELLIPSIS>`, | ||
:ref:`type annotations <annotating-callables>`, |
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.
The link goes to callables (Callable[..., T]
meaning a gradual type covering callables with any sets of arguments), but this is not the only use in typing. It's also used for variable-length tuples (tuple[int, ...]
), to represent an omitted default value in stubs or overloads (def f(x: int = ...) -> None:
), and as an empty body for a function in stubs and a few other contexts (def f(x: int) -> None: ...
).
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 definitely don't have the right links, i wanted to get the language right first.
The latest commits address your latest comments. Thank you for the comments and suggestions. |
@@ -277,6 +278,12 @@ at a more abstract level. The :keyword:`!pass` is silently ignored:: | |||
... pass # Remember to implement this! | |||
... | |||
|
|||
For this last case, many people use the ellipsis literal :code:`...` instead of |
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.
For this last case, many people use the ellipsis literal :code:`...` instead of | |
For this last case, many people use the Ellipsis literal :code:`...` instead of |
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.
Here, I think it is lowercase. Because it is the ellipsis mark, not the object one. Like here: https://docs.python.org/3.13/library/constants.html#Ellipsis
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.
ok.
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 so, it does evaluate to the Ellipsis singleton, even if that value is not used.
>>> ast.parse('def f(): ...').body[0].body[0].value
Constant(value=Ellipsis, kind=None)
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.
A few small tweaks and it's ready to go.
Co-authored-by: Ned Batchelder <[email protected]>
Co-authored-by: Ned Batchelder <[email protected]>
Co-authored-by: Ned Batchelder <[email protected]>
Thanks @adorilson for the PR, and @nedbat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Thanks @adorilson for the PR, and @nedbat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
* Doc: Change Ellipsis doc at library/constants * Doc: Change Ellipsis doc at library/stdtypes * Doc: Add NumPy reference into Ellipsis doc at library/stdtypes * Doc: Add Ellipsis reference into the pass statement section at tutorial * Doc: Update Ellipsis doc concerns assignments at library/constants * Update Doc/library/stdtypes.rst Co-authored-by: Stan Ulbrych <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/constants.rst) Co-authored-by: Éric <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/stdtypes.rst) Co-authored-by: Éric <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/stdtypes.rst) Co-authored-by: Éric <[email protected]> * Doc: Remove pretty printers reference from Ellipsis doc at library/stdtypes * Doc: Update index concerns Ellipsis object and pass statement * Doc: Improve Ellipsis doc at library/constants * Doc: Improve Ellipsis doc at library/stdtypes * Doc: Change the "..." glossary entry to mention the Ellipsis object * Doc: Some improvements concern ellipsis into typing doc * Minor update Doc/tutorial/controlflow.rst Co-authored-by: Ned Batchelder <[email protected]> * Update Doc/library/constants.rst Co-authored-by: Ned Batchelder <[email protected]> * Update Doc/library/stdtypes.rst Co-authored-by: Ned Batchelder <[email protected]> --------- (cherry picked from commit 88665de) Co-authored-by: Adorilson Bezerra <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Éric <[email protected]> Co-authored-by: Ned Batchelder <[email protected]>
* Doc: Change Ellipsis doc at library/constants * Doc: Change Ellipsis doc at library/stdtypes * Doc: Add NumPy reference into Ellipsis doc at library/stdtypes * Doc: Add Ellipsis reference into the pass statement section at tutorial * Doc: Update Ellipsis doc concerns assignments at library/constants * Update Doc/library/stdtypes.rst Co-authored-by: Stan Ulbrych <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/constants.rst) Co-authored-by: Éric <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/stdtypes.rst) Co-authored-by: Éric <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/stdtypes.rst) Co-authored-by: Éric <[email protected]> * Doc: Remove pretty printers reference from Ellipsis doc at library/stdtypes * Doc: Update index concerns Ellipsis object and pass statement * Doc: Improve Ellipsis doc at library/constants * Doc: Improve Ellipsis doc at library/stdtypes * Doc: Change the "..." glossary entry to mention the Ellipsis object * Doc: Some improvements concern ellipsis into typing doc * Minor update Doc/tutorial/controlflow.rst Co-authored-by: Ned Batchelder <[email protected]> * Update Doc/library/constants.rst Co-authored-by: Ned Batchelder <[email protected]> * Update Doc/library/stdtypes.rst Co-authored-by: Ned Batchelder <[email protected]> --------- (cherry picked from commit 88665de) Co-authored-by: Adorilson Bezerra <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Éric <[email protected]> Co-authored-by: Ned Batchelder <[email protected]>
GH-138439 is a backport of this pull request to the 3.13 branch. |
GH-138440 is a backport of this pull request to the 3.14 branch. |
) (cherry picked from commit 88665de) Co-authored-by: Adorilson Bezerra <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Éric <[email protected]> Co-authored-by: Ned Batchelder <[email protected]>
* Doc: Change Ellipsis doc at library/constants * Doc: Change Ellipsis doc at library/stdtypes * Doc: Add NumPy reference into Ellipsis doc at library/stdtypes * Doc: Add Ellipsis reference into the pass statement section at tutorial * Doc: Update Ellipsis doc concerns assignments at library/constants * Update Doc/library/stdtypes.rst Co-authored-by: Stan Ulbrych <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/constants.rst) Co-authored-by: Éric <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/stdtypes.rst) Co-authored-by: Éric <[email protected]> * Doc: Fix grammar on Ellipsis docs (library/stdtypes.rst) Co-authored-by: Éric <[email protected]> * Doc: Remove pretty printers reference from Ellipsis doc at library/stdtypes * Doc: Update index concerns Ellipsis object and pass statement * Doc: Improve Ellipsis doc at library/constants * Doc: Improve Ellipsis doc at library/stdtypes * Doc: Change the "..." glossary entry to mention the Ellipsis object * Doc: Some improvements concern ellipsis into typing doc * Minor update Doc/tutorial/controlflow.rst Co-authored-by: Ned Batchelder <[email protected]> * Update Doc/library/constants.rst Co-authored-by: Ned Batchelder <[email protected]> * Update Doc/library/stdtypes.rst Co-authored-by: Ned Batchelder <[email protected]> --------- Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Éric <[email protected]> Co-authored-by: Ned Batchelder <[email protected]>
After a discuss thread, this PR updates the Ellipsis documentation.
📚 Documentation preview 📚: https://cpython-previews--138306.org.readthedocs.build/