Document that return-less user-defined functions return None#126769
Conversation
|
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. |
|
Tutorial https://docs.python.org/3/tutorial/controlflow.html#defining-functions has a mention that the function without return returns |
asvetlov
left a comment
There was a problem hiding this comment.
Looks good to me. The clarification sentence is short and doesn't blow up the paragraph.
|
Do we want to backport this? |
willingc
left a comment
There was a problem hiding this comment.
Makes good sense to me. I've made a small working suggestion to be a bit more precise.
I think backporting makes sense.
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
|
Thanks @jmarshall for the PR, and @asvetlov for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
|
GH-126822 is a backport of this pull request to the 3.13 branch. |
|
GH-126823 is a backport of this pull request to the 3.12 branch. |
…H-126769) (#126823) Document that return-less user-defined functions return None (GH-126769) (cherry picked from commit e0692f1) Co-authored-by: John Marshall <jmarshall@hey.com> Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
…H-126769) (#126822) Document that return-less user-defined functions return None (GH-126769) (cherry picked from commit e0692f1) Co-authored-by: John Marshall <jmarshall@hey.com> Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
…126769) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
…126769) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
I hunted through Calls, Function definitons, and Execution model, but did not spot any text actually specifying that
Noneis returned by user-defined functions that fall off the end of their code block without encountering areturnstatement.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/