bpo-35506: Remove redundant and incorrect links from keywords. (GH-11174)

This commit is contained in:
Serhiy Storchaka 2018-12-19 08:09:46 +02:00 committed by GitHub
parent 82d73554e4
commit 2b57c43f21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 240 additions and 242 deletions

View file

@ -783,7 +783,7 @@ calls :func:`iter` on the container object. The function returns an iterator
object that defines the method :meth:`~iterator.__next__` which accesses
elements in the container one at a time. When there are no more elements,
:meth:`~iterator.__next__` raises a :exc:`StopIteration` exception which tells the
:keyword:`for` loop to terminate. You can call the :meth:`~iterator.__next__` method
:keyword:`!for` loop to terminate. You can call the :meth:`~iterator.__next__` method
using the :func:`next` built-in function; this example shows how it all works::
>>> s = 'abc'

View file

@ -10,8 +10,8 @@ control flow statements known from other languages, with some twists.
.. _tut-if:
:keyword:`if` Statements
========================
:keyword:`!if` Statements
=========================
Perhaps the most well-known statement type is the :keyword:`if` statement. For
example::
@ -31,16 +31,16 @@ example::
More
There can be zero or more :keyword:`elif` parts, and the :keyword:`else` part is
optional. The keyword ':keyword:`elif`' is short for 'else if', and is useful
to avoid excessive indentation. An :keyword:`if` ... :keyword:`elif` ...
:keyword:`elif` ... sequence is a substitute for the ``switch`` or
optional. The keyword ':keyword:`!elif`' is short for 'else if', and is useful
to avoid excessive indentation. An :keyword:`!if` ... :keyword:`!elif` ...
:keyword:`!elif` ... sequence is a substitute for the ``switch`` or
``case`` statements found in other languages.
.. _tut-for:
:keyword:`for` Statements
=========================
:keyword:`!for` Statements
==========================
.. index::
statement: for
@ -48,7 +48,7 @@ to avoid excessive indentation. An :keyword:`if` ... :keyword:`elif` ...
The :keyword:`for` statement in Python differs a bit from what you may be used
to in C or Pascal. Rather than always iterating over an arithmetic progression
of numbers (like in Pascal), or giving the user the ability to define both the
iteration step and halting condition (as C), Python's :keyword:`for` statement
iteration step and halting condition (as C), Python's :keyword:`!for` statement
iterates over the items of any sequence (a list or a string), in the order that
they appear in the sequence. For example (no pun intended):
@ -154,13 +154,13 @@ Later we will see more functions that return iterables and take iterables as arg
.. _tut-break:
:keyword:`break` and :keyword:`continue` Statements, and :keyword:`else` Clauses on Loops
=========================================================================================
:keyword:`!break` and :keyword:`!continue` Statements, and :keyword:`!else` Clauses on Loops
============================================================================================
The :keyword:`break` statement, like in C, breaks out of the innermost enclosing
:keyword:`for` or :keyword:`while` loop.
Loop statements may have an ``else`` clause; it is executed when the loop
Loop statements may have an :keyword:`!else` clause; it is executed when the loop
terminates through exhaustion of the list (with :keyword:`for`) or when the
condition becomes false (with :keyword:`while`), but not when the loop is
terminated by a :keyword:`break` statement. This is exemplified by the
@ -189,9 +189,9 @@ the :keyword:`for` loop, **not** the :keyword:`if` statement.)
When used with a loop, the ``else`` clause has more in common with the
``else`` clause of a :keyword:`try` statement than it does that of
:keyword:`if` statements: a :keyword:`try` statement's ``else`` clause runs
:keyword:`if` statements: a :keyword:`!try` statement's ``else`` clause runs
when no exception occurs, and a loop's ``else`` clause runs when no ``break``
occurs. For more on the :keyword:`try` statement and exceptions, see
occurs. For more on the :keyword:`!try` statement and exceptions, see
:ref:`tut-handling`.
The :keyword:`continue` statement, also borrowed from C, continues with the next
@ -213,8 +213,8 @@ iteration of the loop::
.. _tut-pass:
:keyword:`pass` Statements
==========================
:keyword:`!pass` Statements
===========================
The :keyword:`pass` statement does nothing. It can be used when a statement is
required syntactically but the program requires no action. For example::
@ -231,7 +231,7 @@ This is commonly used for creating minimal classes::
Another place :keyword:`pass` can be used is as a place-holder for a function or
conditional body when you are working on new code, allowing you to keep thinking
at a more abstract level. The :keyword:`pass` is silently ignored::
at a more abstract level. The :keyword:`!pass` is silently ignored::
>>> def initlog(*args):
... pass # Remember to implement this!
@ -331,7 +331,7 @@ Fibonacci series, instead of printing it::
This example, as usual, demonstrates some new Python features:
* The :keyword:`return` statement returns with a value from a function.
:keyword:`return` without an expression argument returns ``None``. Falling off
:keyword:`!return` without an expression argument returns ``None``. Falling off
the end of a function also returns ``None``.
* The statement ``result.append(a)`` calls a *method* of the list object

View file

@ -216,9 +216,9 @@ or, equivalently::
which is more concise and readable.
A list comprehension consists of brackets containing an expression followed
by a :keyword:`for` clause, then zero or more :keyword:`for` or :keyword:`if`
by a :keyword:`!for` clause, then zero or more :keyword:`!for` or :keyword:`!if`
clauses. The result will be a new list resulting from evaluating the expression
in the context of the :keyword:`for` and :keyword:`if` clauses which follow it.
in the context of the :keyword:`!for` and :keyword:`!if` clauses which follow it.
For example, this listcomp combines the elements of two lists if they are not
equal::
@ -330,12 +330,12 @@ See :ref:`tut-unpacking-arguments` for details on the asterisk in this line.
.. _tut-del:
The :keyword:`del` statement
============================
The :keyword:`!del` statement
=============================
There is a way to remove an item from a list given its index instead of its
value: the :keyword:`del` statement. This differs from the :meth:`pop` method
which returns a value. The :keyword:`del` statement can also be used to remove
which returns a value. The :keyword:`!del` statement can also be used to remove
slices from a list or clear the entire list (which we did earlier by assignment
of an empty list to the slice). For example::

View file

@ -114,7 +114,7 @@ The :keyword:`try` statement works as follows.
A :keyword:`try` statement may have more than one except clause, to specify
handlers for different exceptions. At most one handler will be executed.
Handlers only handle exceptions that occur in the corresponding try clause, not
in other handlers of the same :keyword:`try` statement. An except clause may
in other handlers of the same :keyword:`!try` statement. An except clause may
name multiple exceptions as a parenthesized tuple, for example::
... except (RuntimeError, TypeError, NameError):
@ -180,10 +180,10 @@ example::
print(arg, 'has', len(f.readlines()), 'lines')
f.close()
The use of the :keyword:`else` clause is better than adding additional code to
The use of the :keyword:`!else` clause is better than adding additional code to
the :keyword:`try` clause because it avoids accidentally catching an exception
that wasn't raised by the code being protected by the :keyword:`try` ...
:keyword:`except` statement.
that wasn't raised by the code being protected by the :keyword:`!try` ...
:keyword:`!except` statement.
When an exception occurs, it may have an associated value, also known as the
exception's *argument*. The presence and type of the argument depend on the
@ -343,11 +343,11 @@ example::
A *finally clause* is always executed before leaving the :keyword:`try`
statement, whether an exception has occurred or not. When an exception has
occurred in the :keyword:`try` clause and has not been handled by an
:keyword:`except` clause (or it has occurred in an :keyword:`except` or
:keyword:`else` clause), it is re-raised after the :keyword:`finally` clause has
been executed. The :keyword:`finally` clause is also executed "on the way out"
when any other clause of the :keyword:`try` statement is left via a
occurred in the :keyword:`!try` clause and has not been handled by an
:keyword:`except` clause (or it has occurred in an :keyword:`!except` or
:keyword:`!else` clause), it is re-raised after the :keyword:`finally` clause has
been executed. The :keyword:`!finally` clause is also executed "on the way out"
when any other clause of the :keyword:`!try` statement is left via a
:keyword:`break`, :keyword:`continue` or :keyword:`return` statement. A more
complicated example::
@ -376,7 +376,7 @@ complicated example::
As you can see, the :keyword:`finally` clause is executed in any event. The
:exc:`TypeError` raised by dividing two strings is not handled by the
:keyword:`except` clause and therefore re-raised after the :keyword:`finally`
:keyword:`except` clause and therefore re-raised after the :keyword:`!finally`
clause has been executed.
In real world applications, the :keyword:`finally` clause is useful for

View file

@ -317,7 +317,7 @@ reading and writing such files.
It is good practice to use the :keyword:`with` keyword when dealing
with file objects. The advantage is that the file is properly closed
after its suite finishes, even if an exception is raised at some
point. Using :keyword:`with` is also much shorter than writing
point. Using :keyword:`!with` is also much shorter than writing
equivalent :keyword:`try`\ -\ :keyword:`finally` blocks::
>>> with open('workfile') as f:

View file

@ -112,8 +112,8 @@ Note that in general the practice of importing ``*`` from a module or package is
frowned upon, since it often causes poorly readable code. However, it is okay to
use it to save typing in interactive sessions.
If the module name is followed by :keyword:`as`, then the name
following :keyword:`as` is bound directly to the imported module.
If the module name is followed by :keyword:`!as`, then the name
following :keyword:`!as` is bound directly to the imported module.
::