From 9f3416779a61339ce57465c1857a1c040ca0f697 Mon Sep 17 00:00:00 2001 From: Rafael Fontenelle Date: Sat, 18 Jan 2025 16:11:14 -0300 Subject: [PATCH 1/3] Fix indentation of numbered list and literal block --- Doc/faq/programming.rst | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index fa7b22bde1dc6f..a5ce6e398393a8 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1906,28 +1906,28 @@ In the standard library code, you will see several common patterns for correctly using identity tests: 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 -other objects that may have boolean values that evaluate to false. + for ``None``. This reads like plain English in code and avoids confusion + 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 -value. In those situations, you can create a singleton sentinel object -guaranteed to be distinct from other objects. For example, here is how -to implement a method that behaves like :meth:`dict.pop`:: + value. In those situations, you can create a singleton sentinel object + guaranteed to be distinct from other objects. For example, here is how + to implement a method that behaves like :meth:`dict.pop`:: - _sentinel = object() + _sentinel = object() - def pop(self, key, default=_sentinel): - if key in self: - value = self[key] - del self[key] - return value - if default is _sentinel: - raise KeyError(key) - return default + def pop(self, key, default=_sentinel): + if key in self: + value = self[key] + del self[key] + return value + if default is _sentinel: + raise KeyError(key) + return default 3) Container implementations sometimes need to augment equality tests with -identity tests. This prevents the code from being confused by objects such as -``float('NaN')`` that are not equal to themselves. + identity tests. This prevents the code from being confused by objects + such as ``float('NaN')`` that are not equal to themselves. For example, here is the implementation of :meth:`!collections.abc.Sequence.__contains__`:: From ca5eb25a6dbee87b8179bae7f83bc63a63da9758 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 18 Jan 2025 20:41:33 +0000 Subject: [PATCH 2/3] Apply suggestions from code review --- Doc/faq/programming.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index a5ce6e398393a8..ffd4debaeb7d70 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1914,16 +1914,16 @@ correctly using identity tests: guaranteed to be distinct from other objects. For example, here is how to implement a method that behaves like :meth:`dict.pop`:: - _sentinel = object() - - def pop(self, key, default=_sentinel): - if key in self: - value = self[key] - del self[key] - return value - if default is _sentinel: - raise KeyError(key) - return default + _sentinel = object() + + def pop(self, key, default=_sentinel): + if key in self: + value = self[key] + del self[key] + return value + if default is _sentinel: + raise KeyError(key) + return default 3) Container implementations sometimes need to augment equality tests with identity tests. This prevents the code from being confused by objects From ae2ee1d51485ad9f362f1021bb2263e3b86b7250 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 18 Jan 2025 20:45:28 +0000 Subject: [PATCH 3/3] Fix indentation v2 --- Doc/faq/programming.rst | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index ffd4debaeb7d70..776bab1ed5b779 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1912,18 +1912,20 @@ correctly using identity tests: 2) Detecting optional arguments can be tricky when ``None`` is a valid input value. In those situations, you can create a singleton sentinel object guaranteed to be distinct from other objects. For example, here is how - to implement a method that behaves like :meth:`dict.pop`:: - - _sentinel = object() - - def pop(self, key, default=_sentinel): - if key in self: - value = self[key] - del self[key] - return value - if default is _sentinel: - raise KeyError(key) - return default + to implement a method that behaves like :meth:`dict.pop`: + + .. code-block:: python + + _sentinel = object() + + def pop(self, key, default=_sentinel): + if key in self: + value = self[key] + del self[key] + return value + if default is _sentinel: + raise KeyError(key) + return default 3) Container implementations sometimes need to augment equality tests with identity tests. This prevents the code from being confused by objects