This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document '_' in interpreter tutorial
Type: behavior Stage: patch review
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: ShubhamKJha, docs@python, eric.smith, remi.lapeyre, shihai1991, wyz23x2, xtreak
Priority: normal Keywords: patch

Created on 2020-07-25 12:54 by wyz23x2, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 21654 open wyz23x2, 2020-07-28 08:03
PR 21657 open wyz23x2, 2020-07-28 11:55
Messages (15)
msg374260 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-25 12:54
>>> (None and True)
>>> print(_)
False
>>> print((None and True))  # Not same?!
None
>>> 

This isn't right.

P.S. What component should this be? IDLE? It's the shell, not just IDLE. Core? Not that deep!
msg374261 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-07-25 13:09
Hi wyz23x2, did you do that from a clean interpreter?

_ is set to the last non-None result: https://github.com/python/cpython/blob/dd8a93e23b5c4f9290e1cea6183d97eb9b5e61c0/Python/sysmodule.c#L690-L696

So what you are seeing is that (None and True) is None, but _ is set to some value that you got from a previous input.

I think the component for this report is "Interpreter core".
msg374262 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-07-25 13:12
This behaviour is documented at https://docs.python.org/3/library/sys.html#sys.displayhook.
msg374263 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-25 13:21
I think this should be documented more clearly. Or else users might feel surprised:
>>> print(123)
123
>>> _
Traceback (most recent call last):                                                                                            
    File "<stdin>", line 1, in <module>                                                                                       
NameError: name '_' is not defined 
>>> # There is an expression!?
msg374264 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-07-25 13:25
I haven't checked to see what's documented. I'm sure we'd accept a patch that improves the documentation if it's lacking.
msg374266 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-07-25 13:32
There is also some docs for _ at https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers
msg374267 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-25 13:36
But there's nothing in https://docs.python.org/3/tutorial/interpreter.html. It should be stated there.
msg374329 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-07-26 16:03
>I haven't checked to see what's documented. I'm sure we'd accept a patch that improves the documentation if it's lacking.
+1
msg374390 - (view) Author: Shubham Kumar Jha (ShubhamKJha) * Date: 2020-07-27 15:52
The link provided by Karthikeyan Singaravelan doesn't mention that `_` would only get the not-None values. It is a part of interpreter and hence should be documented there. If no one is working on a patch, I would like to submit one.
msg374450 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-28 02:05
Submmited PR 21650. Should we also mention it in:
https://docs.python.org/3/tutorial/interpreter.html
or
https://docs.python.org/3/tutorial/appendix.html
?

(Matching the title of the issue)
msg374451 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-07-28 02:11
I think it should be mentioned in https://docs.python.org/3/tutorial/appendix.html#tut-interac, since that's the link that https://docs.python.org/3/tutorial/interpreter.html#interactive-mode uses for it's "for more information" link. This seems like a "more information" kind of thing, to me.
msg374452 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-28 02:17
If no one wants to work on it, I'll pick up that patch.
Should it be section 16.1.5? If not, what section should it fit into?
msg374453 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-07-28 02:26
I think it should be in a new section. But I'd put it as a 16.1.2 and push the others down. It seems like a more important piece of information than shebangs and startup files in interactive mode. Or maybe I'd even put it first.

That said, I'm not terribly great at writing documentation, so you might want some other opinions.
msg374454 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-28 02:27
I agree it's more important.
Working.
msg374455 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-28 02:38
Submmited PR 21651.
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85566
2020-07-28 12:13:27wyz23x2setpull_requests: - pull_request20790
2020-07-28 11:55:15wyz23x2setpull_requests: + pull_request20802
2020-07-28 08:57:05wyz23x2setpull_requests: - pull_request20792
2020-07-28 08:03:01wyz23x2setpull_requests: + pull_request20796
2020-07-28 02:38:38wyz23x2setmessages: + msg374455
2020-07-28 02:38:01wyz23x2setpull_requests: + pull_request20792
2020-07-28 02:27:33wyz23x2setmessages: + msg374454
2020-07-28 02:26:01eric.smithsetmessages: + msg374453
2020-07-28 02:17:02wyz23x2setmessages: + msg374452
2020-07-28 02:11:29eric.smithsetmessages: + msg374451
2020-07-28 02:06:42wyz23x2settitle: Document '_' in interpreter in shell tutorial -> Document '_' in interpreter tutorial
2020-07-28 02:05:45wyz23x2setmessages: + msg374450
2020-07-28 02:02:20wyz23x2setkeywords: + patch
stage: patch review
pull_requests: + pull_request20790
2020-07-27 15:52:07ShubhamKJhasetnosy: + ShubhamKJha
messages: + msg374390
2020-07-26 16:03:53shihai1991setnosy: + shihai1991
messages: + msg374329
2020-07-25 13:37:16wyz23x2setnosy: + xtreak
2020-07-25 13:36:52wyz23x2settitle: Make '_' behavior in shell more clear -> Document '_' in interpreter in shell tutorial
nosy: - xtreak

messages: + msg374267

components: - Interpreter Core
2020-07-25 13:32:19xtreaksetnosy: + xtreak
messages: + msg374266
2020-07-25 13:25:04eric.smithsetnosy: + eric.smith
messages: + msg374264
2020-07-25 13:21:44wyz23x2settitle: Behiavior of '_' strange in shell -> Make '_' behavior in shell more clear
nosy: + docs@python

messages: + msg374263

assignee: docs@python
components: + Documentation
2020-07-25 13:12:46remi.lapeyresetmessages: + msg374262
2020-07-25 13:09:45remi.lapeyresetnosy: + remi.lapeyre
messages: + msg374261
components: + Interpreter Core
2020-07-25 12:54:28wyz23x2create