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-110383: Update dictget,fromkeys, andsetdefault signatures in docs#119330

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

Conversation

johnlandonwood
Copy link
Contributor

@johnlandonwoodjohnlandonwood commentedMay 21, 2024
edited
Loading

Small update to address "list of errata: 2" in#110383, by updating the signature of dict methodsget,pop,fromkeys, andsetdefault in the docs.


📚 Documentation preview 📚:https://cpython-previews--119330.org.readthedocs.build/

@ghost
Copy link

ghost commentedMay 21, 2024
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-appbedevere-appbot added docsDocumentation in the Doc dir skip news awaiting review labelsMay 21, 2024
@encukou
Copy link
Member

encukou commentedMay 21, 2024
edited
Loading

Thank you!

Please also remove the square brackets: those are another way of saying that the argument is optional, they aren't needed if the default value is given.

This change makes theget docs inconsistent withfromkeys,pop, andsetdefault. Do you want to update those as well?

@erlend-aasland
Copy link
Contributor

Thanks for the PR! Changes like this are ... controversial. There's a group of core devs who prefer the(a[, b]) signatures, and there's a groupe of core devs who prefer the(a, b=None) signatures. The problem with the former is that they do not work well withinspect, so a lot of people want to changeinspect instead.

Moreover, this PR introduces an inconsistency when we compareget() to the surrounding documented methods. The "bracket-without-default" notation is predominantly used, soiff this should be changed, one would have to take this whole section into account.

So, sorry, I think we have to reject this particular change for now. IMO, it should not be in the TODO list in the issue; changes like this are controversial, and thus no good match as a beginner PR/issue :(

@johnlandonwood
Copy link
ContributorAuthor

@encukou and@erlend-aasland - thank you for the feedback! No worries, I wasn't aware of the controversy around those notations. I just saw it in that issue and it looked like a layup, but things are often more complex than they seem. I appreciate the context :)

erlend-aasland reacted with heart emoji

@erlend-aasland
Copy link
Contributor

I just had a talk with Petr, and I see now that this particular change isnot in the controversial camp :) Itdoes make sense to align the docs with the docstring; so let's land this!

@erlend-aaslanderlend-aasland added needs backport to 3.12only security fixes needs backport to 3.13bugs and security fixes labelsMay 21, 2024
@johnlandonwood
Copy link
ContributorAuthor

johnlandonwood commentedMay 21, 2024
edited
Loading

I just had a talk with Petr, and I see now that this particular change isnot in the controversial camp :) Itdoes make sense to align the docs with the docstring; so let's land this!

Great to hear! I just updatedget and the other surrounding methods (fromkeys,pop, andsetdefault) for consistency. Let me know if anything looks off.

erlend-aasland reacted with hooray emoji

@johnlandonwood
Copy link
ContributorAuthor

johnlandonwood commentedMay 21, 2024
edited
Loading

Wait, one point of confusion - should the dosctring forpop be updated too, to mention that None is the default? Or does the raising of the KeyError cover that?

@johnlandonwoodjohnlandonwood changed the titlegh-110383: Update default to default=None in dict .get() docgh-110383: Update dictget,pop,fromkeys, andsetdefault signatures in docsMay 21, 2024
@erlend-aasland
Copy link
Contributor

Wait, one point of confusion - should the dosctring forpop be updated too, to mention that None is the default? Or does the raising of the KeyError cover that?

Well, it is not that easy; you'd have to change the Argument Clinic input and regenerate the parsing code:

/*[clinic input]
dict.pop
key: object
default: object = NULL
/
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise,
raise a KeyError.
[clinic start generated code]*/
staticPyObject*
dict_pop_impl(PyDictObject*self,PyObject*key,PyObject*default_value)
/*[clinic end generated code: output=3abb47b89f24c21c input=e221baa01044c44c]*/
{
return_PyDict_Pop((PyObject*)self,key,default_value);
}

So,that change would look like this1:

diff --git a/Objects/dictobject.c b/Objects/dictobject.cindex 985a326a176..c976a0c868f 100644--- a/Objects/dictobject.c+++ b/Objects/dictobject.c@@ -4378,7 +4378,7 @@ dict_clear_impl(PyDictObject *self) dict.pop      key: object-    default: object = NULL+    default: object = None     /  D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

Footnotes

  1. combined withmake clinic

@erlend-aasland
Copy link
Contributor

I think we shouldconsider leaving thepop() change out; what do you think,@encukou? Contrary to the other methods,pop() does not actually default toNone; in the implementation it defaults toNULL.

@rhettinger
Copy link
Contributor

Except forpop, these look fine to me.

erlend-aasland reacted with thumbs up emoji

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@erlend-aaslanderlend-aaslandenabled auto-merge (squash)May 21, 2024 20:47
@erlend-aaslanderlend-aasland changed the titlegh-110383: Update dictget,pop,fromkeys, andsetdefault signatures in docsgh-110383: Update dictget,fromkeys, andsetdefault signatures in docsMay 21, 2024
@erlend-aasland
Copy link
Contributor

Thank you,@johnlandonwood, and congrats on landing your first PR :)

johnlandonwood reacted with heart emoji

@johnlandonwood
Copy link
ContributorAuthor

Thank you,@johnlandonwood, and congrats on landing your first PR :)

No, thanks to you and the others for what you do! Feels great!

erlend-aasland reacted with heart emoji

@rhettinger
Copy link
Contributor

rhettinger commentedMay 21, 2024
edited
Loading

Hmm, I think I remember why these got skipped in all of the past sweeps. The issue was that the bracketless form implied that keyword arguments could be used. Also, there was a decision to avoid use/ in signatures in the docs because it tends to confuse users.

Also, it looks like the actual help signatures sometimes look terrible and we don't want that to spill to the main docs:

>>> help(dict.pop)Help on method_descriptor:pop(self, key, default=<unrepresentable>, /) unbound builtins.dict method    D.pop(k[,d]) -> v, remove specified key and return the corresponding value.    If the key is not found, return the default if given; otherwise,    raise a KeyError.

Go ahead and do want you want. I don't have an opinion. I just know that these were intentionally not changed during past sweeps.

johnlandonwood reacted with eyes emoji

@erlend-aaslanderlend-aasland merged commit0e3c8cd intopython:mainMay 22, 2024
@miss-islington-app

This comment has been minimized.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 22, 2024
…s with docstrings (pythonGH-119330)(cherry picked from commit0e3c8cd)Co-authored-by: Landon Wood <landon@elkrange.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 22, 2024
…s with docstrings (pythonGH-119330)(cherry picked from commit0e3c8cd)Co-authored-by: Landon Wood <landon@elkrange.com>
@bedevere-app
Copy link

GH-119370 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMay 22, 2024
@bedevere-app
Copy link

GH-119371 is a backport of this pull request to the3.12 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelMay 22, 2024
erlend-aasland pushed a commit that referenced this pull requestMay 22, 2024
…cs with docstrings (GH-119330) (#119371)(cherry picked from commit0e3c8cd)Co-authored-by: Landon Wood <landon@elkrange.com>
erlend-aasland pushed a commit that referenced this pull requestMay 22, 2024
…cs with docstrings (GH-119330) (#119370)(cherry picked from commit0e3c8cd)Co-authored-by: Landon Wood <landon@elkrange.com>
estyxx pushed a commit to estyxx/cpython that referenced this pull requestJul 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

Assignees
No one assigned
Labels
docsDocumentation in the Doc dirskip news
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@johnlandonwood@encukou@erlend-aasland@rhettinger

[8]ページ先頭

©2009-2025 Movatter.jp