-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-85566: State interpreter var "_" in appendix of tutorial #21654
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
base: main
Are you sure you want to change the base?
Conversation
Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst
Outdated
Show resolved
Hide resolved
Updated. |
There is a bug in Travis CI. Failed example:
_ # Not defined yet
Expected:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_
NameError: name '_' is not defined
Got:
369 Uh... That must be because the prev. process return value in the bot is 369, but it's a new interpreter in the example. |
Same in doc check ╮(╯▽╰)╭ Failed example:
_ # Not defined yet
Expected:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_
NameError: name '_' is not defined
Got:
time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1) That must be the recent value too. |
IMO the doctest should be done in a separate namespace. What if it's something like |
There is a special variable ``_`` in interactive mode, which stores the result of the last | ||
evaluated expression. If the last expression evaluated to ``None``, then the value of ``_`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking the two commas here are somewhat superfluous. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some grepping:
sk@note:~/src/cpython $ git grep '[[:space:]]`None' Doc/ # no hits
sk@note:~/src/cpython $ git grep -F '``None``' Doc/|wc -l
1396
Re: doctest failures. We trust devs not to put attacks in doctests (honestly, if we can't trust devs there are a lot of other possible attack vectors :-). For contributors we trust reviewers to review the code before running it. So about how to unbreak this, I think there's a way to insert something in the source file that is executed but not displayed. Look here: https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html (testsetup) |
Not really part of Error handling, hence should be a new section. |
@rhettinger Can you help this forward? |
@rhettinger ^^ |
cc: @merwok |
The following commit authors need to sign the Contributor License Agreement: |
|
||
>>> _ # Not defined yet | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
_ | ||
NameError: name '_' is not defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> _ # Not defined yet | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
_ | |
NameError: name '_' is not defined | |
.. doctest:: | |
:options: +SKIP | |
>>> _ # Not defined yet | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
_ | |
NameError: name '_' is not defined |
I doubt this example is fixable. Either you could remove one or exclude entire block from testing, as suggested.
There is a special variable ``_`` in interactive mode, which stores the result of the last | ||
evaluated expression. If the last expression evaluated to ``None``, then the value of ``_`` | ||
is not updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a special variable ``_`` in interactive mode, which stores the result of the last | |
evaluated expression. If the last expression evaluated to ``None``, then the value of ``_`` | |
is not updated. | |
There is a special variable ``_`` in interactive mode, which is updated with the result | |
of the last evaluated expression, unless it was ``None``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the verb should be in the past: unless it was None
but would like a native speaker to confirm!
Added "Special ``_`` Variable" section to the "16. Appendix" part of Python tutorial. | ||
|
||
It includes the define of ``_`` and an example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added "Special ``_`` Variable" section to the "16. Appendix" part of Python tutorial. | |
It includes the define of ``_`` and an example. | |
Added "Special ``_`` Variable" section to the "16. Appendix" part of Python tutorial. |
@@ -53,6 +53,32 @@ Typing an interrupt while a command is executing raises the | |||
:exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try` | |||
statement. | |||
|
|||
.. _tut-var: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something less generic / cryptic:
.. _tut-var: | |
.. _tut-underscore-variable: |
Continue of the not-working #21651 .
This patch states the special variable
_
in interactive mode and also includes an example.