GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-91485: Doc: Using Python syntax to document builtin Python functions. by JulienPalard · Pull Request #96579 · python/cpython

Conversation

@JulienPalard

@JulienPalard JulienPalard commented Sep 5, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I tried my idea at documenting Python functions using only Python syntax (avoiding manpages-like brackets to denote optional arguments), please tell me what you think.

It sometimes went "badly", like:

-.. class:: set([iterable])
+.. class:: set(iterable=())

where I "had" to use an empty tuple because it would have looked very recursive to use a set here, like set(iterable=set()). It's also a lie: it's not an empty tuple by default (it's a C NULL), but there's no practical difference for the reader.

Sometimes the change is more neutral, like in:

-.. awaitablefunction:: anext(async_iterator[, default])
+.. awaitablefunction:: anext(async_iterator)
+                       anext(async_iterator, default)

or:

-.. function:: max(iterable, *[, key, default])
-              max(arg1, arg2, *args[, key])
+.. function:: max(iterable, /, *, key=None)
+              max(iterable, /, *, default, key=None)
+              max(arg1, arg2, *args, key=None)

(where I'm happy to remove , *[, because it hurt my eyes.)

Sometimes it's good as it add information:

-.. class:: complex([real[, imag]])
+.. class:: complex(real=0, imag=0)

Or make more explicit where it's OK to pass None and where it's not, like in:

-.. class:: super([type[, object-or-type]])
+.. class:: super()
+           super(type, object_or_type=None)

I bet you think « People should know this syntax, or learn it anyway », but I don't think so, I mean yes they will learn it anyway, but why forcing them to learn it at the same time as they learn basic Python functions? Learning one thing at a time is complicated enough.

Many are alone facing those pages and showing them:

complex(real=0, imag=0)

teach them how to implement default arguments in their own functions, and explicitly show them what happen when they don't give the values, while:

complex([real[, imag]])

don't.

  • Issue: documentation for function arguments #91485

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting core review docs Documentation in the Doc dir skip news labels Sep 5, 2022
entwanne
entwanne reviewed Sep 5, 2022
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JulienPalard

JulienPalard commented Sep 21, 2022

Copy link
Copy Markdown
Member Author

I don't like:

.. class:: list(iterable=[])

for an acute reader it scream "the default empty list is reused!", I have to change this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra
JelleZijlstra reviewed Oct 7, 2022
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

JulienPalard and others added 5 commits October 13, 2022 12:34
@JulienPalard
Doc: Using Python syntax to document builtin Python functions.
2abd2d3
@JulienPalard @entwanne
Update Doc/library/functions.rst
baf3065
Co-authored-by: Antoine Rozo <[email protected]>
@JulienPalard
Added a newline by mistake.
71c909f
@JulienPalard
Avoid messing around fake default argument.
82bf578
@JulienPalard @JelleZijlstra
Update Doc/library/functions.rst
edbfcd6
Co-authored-by: Jelle Zijlstra <[email protected]>
AA-Turner
AA-Turner reviewed Oct 13, 2022
View reviewed changes

@AA-Turner AA-Turner left a comment

Copy link
Copy Markdown
Member

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.

Biggest comment is on map().

A

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/functions.rst Outdated
Comment on lines +1021 to +1026
.. function:: map(function, *iterables)

Return an iterator that applies *function* to every item of *iterable*,
yielding the results. If additional *iterable* arguments are passed,
Return an iterator that applies *function* to every item of *iterables*,
yielding the results. If additional *iterables* arguments are passed,

@AA-Turner AA-Turner Oct 13, 2022

Copy link
Copy Markdown
Member

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 the new wording is true, e.g.:

>>> from operator import add
>>> for x in map(add, [1, 2, 3, 4, 5], [10, 20, 30, 40, 50]):
>>>     print(x)
>>> 
11
22
33
44
55

So it doesn't apply function to every item of iterables, but to every item of zip(*iterables).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JulienPalard JulienPalard Oct 13, 2022

Copy link
Copy Markdown
Member Author

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, we have to rephrase it..

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JulienPalard JulienPalard Oct 13, 2022

Copy link
Copy Markdown
Member Author

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 7aca0e5 ? map(int) is not valid anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JulienPalard JulienPalard Oct 13, 2022

Copy link
Copy Markdown
Member Author

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 move the / in the following commit as iterable can't be given by name)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@JulienPalard
Try to be exhaustive about what can and can't be done with builtins.
92a3bb0
@JulienPalard
JulienPalard force-pushed the mdk-stick-to-python-syntax branch from 0bf0db5 to 92a3bb0 Compare October 13, 2022 12:51
@JulienPalard

JulienPalard commented Oct 13, 2022

Copy link
Copy Markdown
Member Author

@AA-Turner wow we were doing it in the same time, I just pushed my part, we'll be able to diff them to see if we agree :D

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JulienPalard and others added 6 commits October 13, 2022 14:53
@JulienPalard @AA-Turner
Update Doc/library/functions.rst
2d3e6df
Co-authored-by: Adam Turner <[email protected]>
@JulienPalard @AA-Turner
Update Doc/library/functions.rst
3dd97eb
Co-authored-by: Adam Turner <[email protected]>
@JulienPalard
Complex can take a string, thanks AA-Turner.
f6457e7
@JulienPalard
FIX: map prototype.
7aca0e5
@JulienPalard
iterable can't be given by name.
b289475
@JulienPalard
There's no arguments that can be named here, so this slash was useless.
fb11b2d
AA-Turner
AA-Turner approved these changes Oct 13, 2022
View reviewed changes

@AA-Turner AA-Turner left a comment

Copy link
Copy Markdown
Member

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.

Thanks! I think this is good to merge personally.

A

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AA-Turner AA-Turner added needs backport to 3.10 needs backport to 3.11 only security fixes labels Oct 13, 2022
@JulienPalard
JulienPalard merged commit 3c4cbd1 into python:main Oct 15, 2022
@miss-islington

miss-islington commented Oct 15, 2022

Copy link
Copy Markdown
Contributor

Thanks @JulienPalard for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting core review label Oct 15, 2022
@JulienPalard
JulienPalard deleted the mdk-stick-to-python-syntax branch October 15, 2022 10:19
@miss-islington

miss-islington commented Oct 15, 2022

Copy link
Copy Markdown
Contributor

Sorry, @JulienPalard, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 3c4cbd177f36777a04e78eb07ce20367560a66d3 3.10

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Oct 15, 2022

Copy link
Copy Markdown

GH-98276 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington miss-islington assigned JulienPalard Oct 15, 2022
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Oct 15, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 15, 2022
@JulienPalard @miss-islington
pythongh-91485: Doc: Using Python syntax to document builtin Python f…
33f6dfe
…unctions. (pythonGH-96579)

(cherry picked from commit 3c4cbd1)

Co-authored-by: Julien Palard <[email protected]>
miss-islington added a commit that referenced this pull request Oct 15, 2022
@miss-islington @JulienPalard
gh-91485: Doc: Using Python syntax to document builtin Python functio…
42d536c
…ns. (GH-96579)

(cherry picked from commit 3c4cbd1)

Co-authored-by: Julien Palard <[email protected]>
JulienPalard added a commit that referenced this pull request Oct 17, 2022
@JulienPalard
Revert "gh-91485: Doc: Using Python syntax to document builtin Python…
cc68058
… functions. (GH-96579)"

This reverts commit 3c4cbd1.
@JulienPalard JulienPalard mentioned this pull request Oct 17, 2022
Revert "gh-91485: Doc: Using Python syntax to document builtin Python functions." #98352
Closed
pablogsal pushed a commit that referenced this pull request Oct 22, 2022
@miss-islington @JulienPalard @pablogsal
gh-91485: Doc: Using Python syntax to document builtin Python functio…
3737a0e
…ns. (GH-96579)

(cherry picked from commit 3c4cbd1)

Co-authored-by: Julien Palard <[email protected]>
@wjandrea wjandrea mentioned this pull request Dec 26, 2022
eval() documentation is wrong about keyword arguments #100546
Closed
@hauntsaninja hauntsaninja removed the needs backport to 3.10 label Dec 27, 2022
@hauntsaninja hauntsaninja mentioned this pull request Dec 27, 2022
gh-100546: Remove incorrect positional-only marker from eval #100547
Merged
@wimglenn wimglenn mentioned this pull request Aug 8, 2023
Signature of slice is documented incorrectly #107755
Closed
@chris-eibl chris-eibl mentioned this pull request Oct 25, 2024
Built-in function range params discrepancy across versions #125897
Closed
@chris-eibl chris-eibl mentioned this pull request Nov 6, 2024
gh-125897: Use positional-only parameter indicators for range() #125945
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra left review comments
@AA-Turner AA-Turner AA-Turner approved these changes
+1 more reviewer
@entwanne entwanne entwanne left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@JulienPalard JulienPalard

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@JulienPalard @miss-islington @bedevere-bot @JelleZijlstra @entwanne @AA-Turner @hauntsaninja
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.