-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Change docstring of format()
built-in
#96526
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
Comments
The mini-language actually doesn't only apply to strings. Most of those options are actually specific to numeric types. The fallback you mentioned is quite correct though. |
@TeamSpen210 Thank you. I updated the proposal wording to include numeric types. Also, for further verification, I tested |
There's also at least The actual behavior is that (after a few optimizations) it really just calls |
@ericvsmith Thank you for the pointer. I had only checked built-in types (via I'll ponder a bit on how to reformulate this to make it explicit yet simple and readable. While I'm at it, I checked the various These are confusing to me: >>> import inspect; doc = inspect.getdoc
>>> doc(object.__format__)
'Default object formatter'
>>> doc(int.__format__)
'Default object formatter'
>>> doc(bool.__format__)
'Default object formatter.'
>>> doc(bytes.__format__) # as an example of a type without a defined __format__
'Default object formatter.'
>>> doc(decimal.Decimal.__format__)
'Default object formatter.' These I find more helpful, and some may benefit from a pointer to the mini-language: >>> doc(str.__format__)
'Return a formatted version of the string as described by format_spec.'
>>> doc(float.__format__)
'Formats the float according to format_spec.'
>>> doc(complex.__format__)
'Convert to a string according to format_spec.'
>>> doc(datetime.date.__format__)
'Formats self with strftime.'
>>> doc(enum.Enum.__format__)
'Returns format using actual value type unless __str__ has been overridden.'
|
@ericvsmith @TeamSpen210 Your comments helped me think more clearly. I updated the wording and pitch with what I think captures the essence. What do you think? |
I'd suggest tweaking the second sentence a bit, to indicate that the spec has to be empty if no |
What’s the PR number? |
@TeamSpen210 Updated. Thank you. @ericvsmith No PR yet. My intention with posting here was to understand if this kind of a change would be welcomed. I've never done a Python PR before, but happy to try. :) I 8000 s the process described here the current one? |
@mikez Yes, I think that's correct. |
@ericvsmith see PR above. I made two additional changes
|
@ericvsmith @TeamSpen210 To clarify, when I did the pull request, it seems it got auto-assigned to @markshannon as a reviewer. Should I instead have assigned it to one of you? Or, is this reviewer-assignment correct, and I have to expect to wait at least a month or some more for it to get reviewed? (Asking, since I'm new here.) |
I’m not sure why it was assigned to Mark. This is on my list of things to look at the week of October 3, when I’m at a sprint and plan to knock out a bunch of PRs. |
@ericvsmith Thank you for the clarification. (Also odd, I couldn't find any way on Github to reassign it or add you to it, at least not with my current user permissions.) |
I see it as unassigned. I'll assign it to myself. |
@ericvsmith 👍 To clarify, when 8000 I said "assigned" I meant the PR: #96648 |
I see Mark as a reviewer, not assignee. I've assigned the PR to myself. |
@ericvsmith I previously thought of reviewer and assignee as synonymous, but according to this article it seems they're not. I guess for Python "assignee" is relevant here, and reviewer acts more like a CC in email. |
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
The
format.__doc__
currently statesI propose to change this to
While I'm at it, I propose to also clarify the docstrings of
object.__format__
andint.__format__
. (See comment here for current behavior.)Pitch
I saw this documentation today and it confused me as I tried to understand how to format
bytes
. The help prompted me to look athelp('FORMATTING')
which seemed misleading. Only after looking at the C-code offormat()
did I understand what was going on.The main clarifications I added here was:
object.__format__
and pointer to__format__
documentation.type(value).__format__(...)
is returned, notvalue.__format__(...)
Moreover, I propose to remove "format_spec defaults to the empty string", since this is shown already in "help()" through the function signature.
Previous discussion
Note: Updated on 2022-09-03 to include @TeamSpen210's remark.
Note: Updated on 2022-09-05 to include @ericvsmith's remark.
Note: Updated on 2022-09-06 to include @TeamSpen210's remark.
Note: Updated on 2022-09-07 to include new findings upon reading the C code.
The text was updated successfully, but these errors were encountered: