Skip to content

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

Merged
asvetlov merged 2 commits into
python:mainfrom
jmarshall:default-return-none
Nov 14, 2024
Merged

Document that return-less user-defined functions return None#126769
asvetlov merged 2 commits into
python:mainfrom
jmarshall:default-return-none

Conversation

@jmarshall

@jmarshall jmarshall commented Nov 12, 2024

Copy link
Copy Markdown
Contributor

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 jmarshall requested a review from willingc as a code owner November 12, 2024 23:00
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news awaiting review labels Nov 12, 2024
Comment thread Doc/reference/expressions.rst
@jmarshall

jmarshall commented Nov 13, 2024

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

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

@asvetlov asvetlov left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

Do we want to backport this?

@willingc willingc left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread Doc/reference/expressions.rst Outdated
@willingc willingc added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Nov 13, 2024
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
@asvetlov asvetlov enabled auto-merge (squash) November 14, 2024 07:16
@asvetlov asvetlov merged commit e0692f1 into python:main Nov 14, 2024
@miss-islington-app

Copy link
Copy Markdown

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 <jmarshall@hey.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
@bedevere-app

bedevere-app Bot commented Nov 14, 2024

Copy link
Copy Markdown

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 <jmarshall@hey.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
@bedevere-app

bedevere-app Bot commented Nov 14, 2024

Copy link
Copy Markdown

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 only 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 <jmarshall@hey.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
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 <jmarshall@hey.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
picnixz pushed a commit to picnixz/cpython that referenced this pull request Dec 8, 2024
…126769)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
…126769)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
@jmarshall jmarshall deleted the default-return-none branch March 17, 2025 09:58
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