GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-137609: Update signatures of builtins in the documentation by serhiy-storchaka · Pull Request #137610 · python/cpython Conversation
|
|
See also #137611. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I approve of the issue, the addition of /s, the renamings, and most of the details. The main question for me is relative positioning of / and *args.
Fewer versus more lines is partly style preference and partly technical accuracy, and the signature needed to have an inspect.signature and to write a python version of the same or similar function, versus ease of understanding how to call the function. Are "future multisignatures" a real possibility?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .. class:: bytearray() | ||
| bytearray(source) | ||
| bytearray(source, encoding) | ||
| bytearray(source, encoding, errors) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe only two lines are needed.
| .. class:: bytearray() | |
| bytearray(source) | |
| bytearray(source, encoding) | |
| bytearray(source, encoding, errors) | |
| .. class:: bytearray(source=b'') | |
| bytearray(source, encoding, errors='strict') |
See also #137100, which is also about the text that follows.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Some descriptions have separate signature for no argument, others merge it with a signature with one argument. See for example dict which could be written as dict(mapping_or_iterable=(), **kwargs), but is written as three semantically different signatures. I tried to be more consistent and chose the former variant. But I have no such strong preference.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I prefer fewer lines, and approve of the changes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree here, source=b'' makes it less clear to me that source also accepts e.g. iterables of integers, buffer-protocol, etc. I would suggest:
.. class:: bytearray() bytearray(source, /) bytearray(source, /, encoding, errors='strict')
Note I have suggested to annotate 'source' as positional-only -- I think this makes more sense to users than writing e.g. bytearray(source=my_numpy_array). My IDE & type-checkers also indicates that source=... is an error, as it is annotated as positional-only in typeshed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have made the requested changes; please review again.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| .. class:: bytearray() | ||
| bytearray(source) | ||
| bytearray(source, encoding) | ||
| bytearray(source, encoding, errors) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Some descriptions have separate signature for no argument, others merge it with a signature with one argument. See for example dict which could be written as dict(mapping_or_iterable=(), **kwargs), but is written as three semantically different signatures. I tried to be more consistent and chose the former variant. But I have no such strong preference.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Terry Jan Reedy <[email protected]>
00556ee to
de15f70
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .. _func-str: | ||
| .. class:: str(object='') | ||
| str(object=b'', encoding='utf-8', errors='strict') | ||
| .. class:: str(*, encoding='utf-8', errors='strict') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's technically true that you can pass just the encoding or errors kwargs (like str(encoding='ebcdic')), but it's not practically useful, since you just get an empty string whatever encoding you pass, and I fear it's confusing to users to put this here.
The old docs here feel clearer even if they're not as precise.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should be technically correct.
Several years ago I proposed to deprecate this case, but my proposition was rejected. If it is worth to continue supporting this in code, it is worth to document it. Note that values of encoding and errors are ignored:
>>> str(encoding='spam', errors='ham') ''
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
||
| .. _func-frozenset: | ||
| .. class:: frozenset(iterable=set()) | ||
| .. class:: frozenset(iterable=(), /) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Either approach could work but I like the way it's in the current PR; it's better to have fewer distinct signatures.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Jelle Zijlstra <[email protected]>
|
Reverted changes for signatures with start/end parameters, as this is a separate non-trivial issue (#138134). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ythonGH-137610) Show signatures that match the actual signatures or future multisignatures for all functions, classes and methods in the "builtins" module. (cherry picked from commit 65fb4d1) Co-authored-by: Serhiy Storchaka <[email protected]>
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-138137 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ation (pythonGH-137610) Show signatures that match the actual signatures or future multisignatures for all functions, classes and methods in the "builtins" module. (cherry picked from commit 65fb4d1) Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-138138 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…H-137610) (#138137) Co-authored-by: Serhiy Storchaka <[email protected]>
…ation (pythonGH-137610) (python#138137) Co-authored-by: Serhiy Storchaka <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.