Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-91485: Doc: Using Python syntax to document builtin Python functions.#96579

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@JulienPalard
Copy link
Member

@JulienPalardJulienPalard commentedSep 5, 2022
edited by bedevere-bot
Loading

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, likeset(iterable=set()). It's also a lie: it's not an empty tuple by default (it's a CNULL), 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 passNone 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.

@bedevere-botbedevere-bot added awaiting core review docsDocumentation in the Doc dir skip news labelsSep 5, 2022
@JulienPalard
Copy link
MemberAuthor

I don't like:

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

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

Copy link
Member

@AA-TurnerAA-Turner left a comment

Choose a reason for hiding this comment

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

Biggest comment is onmap().

A

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

>>>from operatorimport add>>>for xinmap(add, [1,2,3,4,5], [10,20,30,40,50]):>>>print(x)>>> 1122334455

So it doesn't applyfunction to every item ofiterables, but to every item ofzip(*iterables).

Copy link
MemberAuthor

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..

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

What about7aca0e5 ?map(int) is not valid anyway.

Copy link
MemberAuthor

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 asiterable can't be given by name)

@JulienPalardJulienPalardforce-pushed themdk-stick-to-python-syntax branch from0bf0db5 to92a3bb0CompareOctober 13, 2022 12:51
@JulienPalard
Copy link
MemberAuthor

@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

Copy link
Member

@AA-TurnerAA-Turner left a 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

@AA-TurnerAA-Turner added needs backport to 3.10only security fixes needs backport to 3.11only security fixes labelsOct 13, 2022
@JulienPalardJulienPalard merged commit3c4cbd1 intopython:mainOct 15, 2022
@miss-islington
Copy link
Contributor

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

@JulienPalardJulienPalard deleted the mdk-stick-to-python-syntax branchOctober 15, 2022 10:19
@miss-islington
Copy link
Contributor

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

@bedevere-bot
Copy link

GH-98276 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelOct 15, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestOct 15, 2022
…unctions. (pythonGH-96579)(cherry picked from commit3c4cbd1)Co-authored-by: Julien Palard <julien@palard.fr>
miss-islington added a commit that referenced this pull requestOct 15, 2022
…ns. (GH-96579)(cherry picked from commit3c4cbd1)Co-authored-by: Julien Palard <julien@palard.fr>
JulienPalard added a commit that referenced this pull requestOct 17, 2022
pablogsal pushed a commit that referenced this pull requestOct 22, 2022
…ns. (GH-96579)(cherry picked from commit3c4cbd1)Co-authored-by: Julien Palard <julien@palard.fr>
@hauntsaninjahauntsaninja removed the needs backport to 3.10only security fixes labelDec 27, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra left review comments

@AA-TurnerAA-TurnerAA-Turner approved these changes

+1 more reviewer

@entwanneentwanneentwanne left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

@JulienPalardJulienPalard

Labels

docsDocumentation in the Doc dirskip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@JulienPalard@miss-islington@bedevere-bot@JelleZijlstra@entwanne@AA-Turner@hauntsaninja

[8]ページ先頭

©2009-2025 Movatter.jp