Skip to content
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

Document that return-less user-defined functions return None #126769

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

jmarshall
Copy link
Contributor

@jmarshall jmarshall commented Nov 12, 2024

I hunted through Calls, Function definitons, and Execution model, but did not spot any text actually specifying that None is returned by user-defined functions that fall off the end of their code block without encountering a return statement.

This adds such text to the description of return values in the Calls section, which IMHO is the most likely place readers would look for it.


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

@jmarshall
Copy link
Contributor Author

jmarshall commented Nov 13, 2024

What would be particularly useful from more experienced Pythonistas would be an indication of whether they think this addition is necessary or a pointer to where this is already documented in the reference documentation (if it is).

(And if it's not already documented somewhere, confirmation that it is actually true!)

ETA: I see it appears in the description of None.

@asvetlov
Copy link
Contributor

Tutorial https://docs.python.org/3/tutorial/controlflow.html#defining-functions has a mention that the function without return returns None.

Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Looks good to me. The clarification sentence is short and doesn't blow up the paragraph.

@ZeroIntensity
Copy link
Member

Do we want to backport this?

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Makes good sense to me. I've made a small working suggestion to be a bit more precise.

I think backporting makes sense.

Doc/reference/expressions.rst Outdated Show resolved Hide resolved
@willingc willingc added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Nov 13, 2024
@asvetlov asvetlov enabled auto-merge (squash) November 14, 2024 07:16
@asvetlov asvetlov merged commit e0692f1 into python:main Nov 14, 2024
25 checks passed
@miss-islington-app
Copy link

Thanks @jmarshall for the PR, and @asvetlov for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 14, 2024
…H-126769)

(cherry picked from commit e0692f1)

Co-authored-by: John Marshall <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
Co-authored-by: Carol Willing <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Nov 14, 2024

GH-126822 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Nov 14, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 14, 2024
…H-126769)

(cherry picked from commit e0692f1)

Co-authored-by: John Marshall <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
Co-authored-by: Carol Willing <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Nov 14, 2024

GH-126823 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Nov 14, 2024
asvetlov added a commit that referenced this pull request Nov 14, 2024
…H-126769) (#126823)

Document that return-less user-defined functions return None (GH-126769)
(cherry picked from commit e0692f1)

Co-authored-by: John Marshall <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
Co-authored-by: Carol Willing <[email protected]>
asvetlov added a commit that referenced this pull request Nov 14, 2024
…H-126769) (#126822)

Document that return-less user-defined functions return None (GH-126769)
(cherry picked from commit e0692f1)

Co-authored-by: John Marshall <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
Co-authored-by: Carol Willing <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants