mirror of
https://github.com/python/cpython.git
synced 2025-08-25 19:24:42 +00:00
gh-128998: Fix indentation of numbered list and literal block (#128999)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
fba475ae6f
commit
e8092e5cdc
1 changed files with 18 additions and 16 deletions
|
@ -1906,28 +1906,30 @@ In the standard library code, you will see several common patterns for
|
||||||
correctly using identity tests:
|
correctly using identity tests:
|
||||||
|
|
||||||
1) As recommended by :pep:`8`, an identity test is the preferred way to check
|
1) As recommended by :pep:`8`, an identity test is the preferred way to check
|
||||||
for ``None``. This reads like plain English in code and avoids confusion with
|
for ``None``. This reads like plain English in code and avoids confusion
|
||||||
other objects that may have boolean values that evaluate to false.
|
with other objects that may have boolean values that evaluate to false.
|
||||||
|
|
||||||
2) Detecting optional arguments can be tricky when ``None`` is a valid input
|
2) Detecting optional arguments can be tricky when ``None`` is a valid input
|
||||||
value. In those situations, you can create a singleton sentinel object
|
value. In those situations, you can create a singleton sentinel object
|
||||||
guaranteed to be distinct from other objects. For example, here is how
|
guaranteed to be distinct from other objects. For example, here is how
|
||||||
to implement a method that behaves like :meth:`dict.pop`::
|
to implement a method that behaves like :meth:`dict.pop`:
|
||||||
|
|
||||||
_sentinel = object()
|
.. code-block:: python
|
||||||
|
|
||||||
def pop(self, key, default=_sentinel):
|
_sentinel = object()
|
||||||
if key in self:
|
|
||||||
value = self[key]
|
def pop(self, key, default=_sentinel):
|
||||||
del self[key]
|
if key in self:
|
||||||
return value
|
value = self[key]
|
||||||
if default is _sentinel:
|
del self[key]
|
||||||
raise KeyError(key)
|
return value
|
||||||
return default
|
if default is _sentinel:
|
||||||
|
raise KeyError(key)
|
||||||
|
return default
|
||||||
|
|
||||||
3) Container implementations sometimes need to augment equality tests with
|
3) Container implementations sometimes need to augment equality tests with
|
||||||
identity tests. This prevents the code from being confused by objects such as
|
identity tests. This prevents the code from being confused by objects
|
||||||
``float('NaN')`` that are not equal to themselves.
|
such as ``float('NaN')`` that are not equal to themselves.
|
||||||
|
|
||||||
For example, here is the implementation of
|
For example, here is the implementation of
|
||||||
:meth:`!collections.abc.Sequence.__contains__`::
|
:meth:`!collections.abc.Sequence.__contains__`::
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue