Skip to content

bpo-46282 Add return value to print() doc #30435

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

Closed
wants to merge 2 commits into from

Conversation

SnoopJ
Copy link
Contributor

@SnoopJ SnoopJ commented Jan 6, 2022

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
@@ -1375,7 +1375,7 @@ are always available. They are listed here in alphabetical order.

Print *objects* to the text stream *file*, separated by *sep* and followed
by *end*. *sep*, *end*, *file*, and *flush*, if present, must be given as keyword
arguments.
arguments. The return value is :const:`None`.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your contribution to Python, but I wonder if this is really necessary. In Python, if a function doesn't explicitly return something else, it always implicitly returns None. We generally don't document this because if we did so everywhere, the documentation would be pretty noisy. Note that this is different from functions which explicitly return None for reasons of their API design.

Copy link
Contributor Author

@SnoopJ SnoopJ Jan 6, 2022

Choose a reason for hiding this comment

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

I do agree that it would be inappropriate to do this everywhere, but I don't think it would hurt anything to mention it for print() specifically (the scope of this PR), short of concern that it's a slippery-slope that leads to "do it for everything" PRs.

I've certainly seen beginners do something = print(...) enough times that when this came up again in #python on Libera IRC I thought I would open an issue on the user's behalf.

Copy link
Member

Choose a reason for hiding this comment

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

Yes it's a slippery slope, but it's also confusing. A user might question "why does the print documentation mention this both other functions don't?" As I mentioned in the bug comment, I think it does users a better service to explain how Python return values work.

Copy link
Member

Choose a reason for hiding this comment

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

I am also torn. print is probably used a lot, and used early in learning. If this page was not library/functions but the tutorial, I would just add the mention!

Two ideas / questions for the PR author:

  • Does the tutorial mention the implicit return of None? If not, should it?
  • Would it help to mention it at the top of this file (too)? (maybe not if people don’t start at the top but use a link that jumps to specific function)

This reminds me of https://bugs.python.org/issue42571 where someone did not know what * and / meant in function signatures, and also did not know to search for it. (BTW to me this shows that Python is right to generally prefer words over symbols, see recent lambda vs => discussion)

Maybe these two issues can be tackled with some text with links at the top of this doc file.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe these two issues can be tackled with some text with links at the top of this doc file.

This occurs to me too. Rather than a one-off, providing information on how Python return values (and maybe also documented function signatures) seems more like teaching someone how to fish rather than giving them a fish.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the tutorial mention the implicit return of None? If not, should it?

The tutorial does mention it...in a fairly roundabout way. Viewing § 4.7 Defining Functions at 1920x1080 on a laptop screen, it's the second page of that section.

Perhaps this PR/issue can be closed in favor of making this property of functions more obvious in the documentation.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this PR/issue can be closed in favor of making this property of functions more obvious in the documentation.

+1

Choose a reason for hiding this comment

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

Personally I think it would be better to have "noisy" documentation that specifies the return value of every single documented function, even if many of them are none. It doesn't take that much space to write "Returns None". Explicit is better than implicit. :-)

@SnoopJ
Copy link
Contributor Author

SnoopJ commented Jan 25, 2022

Closing, will open a separate PR to add a 'breadcrumb' hinting at this "returns None if not specified" property to the top of the builtin functions.

@SnoopJ SnoopJ closed this Jan 25, 2022
@SnoopJ SnoopJ deleted the bpo-46282_doc-print-return-value branch January 25, 2022 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants