-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
gh-116938: Clarify documentation of dict
and dict.update
regarding the positional argument they accept
#125213
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -962,7 +962,7 @@ def clear(self): | |||||||||||||||||||||||
|
||||||||||||||||||||||||
def update(self, other=(), /, **kwds): | ||||||||||||||||||||||||
''' D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. | ||||||||||||||||||||||||
If E present and has a .keys() method, does: for k in E: D[k] = E[k] | ||||||||||||||||||||||||
If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per #116938 (comment) |
||||||||||||||||||||||||
If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v | ||||||||||||||||||||||||
In either case, this is followed by: for k, v in F.items(): D[k] = v | ||||||||||||||||||||||||
Comment on lines
+965
to
967
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I would like it to be more specific:
Suggested change
In the web docs the requirements are strict:
Usage of words class Object:
keys = []
def __iter__(self, /):
return iter(self.keys) This class clearly lacks .keys() method because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine IMO. It's much less important for docstrings to be completely precise than it is for the ReST documentation. The most important thing for the docstrings is for them to be concise and easily readable in a terminal or editor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, my bad. In that case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but the docstring for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this PR the first sentence was updated from Lines 4521 to 4525 in 2982bdb
Consider: class Object:
def keys(self):
return [1, 2]
def __iter__(self):
return [3, 4]
def __getitem__(self, item):
match item:
case 1: return 'one'
case 2: return 'two'
case 3: return 'three'
case 4: return 'four'
return item
print(dict(Object()))
d = {}
d.update(Object())
print(d) Both times the result is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I see what you mean now. Yes, I suppose that could also be clarified. |
||||||||||||||||||||||||
''' | ||||||||||||||||||||||||
|
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.
There is a premature period on line 4674 after closing brace.
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.
Good catch! Want to file a PR to fix it?
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.
#125421