@@ -51,7 +51,7 @@ Motivation
5151==========
5252
5353In May 2021, a question was brought up on the python-dev mailing list
54- [#python-dev-thread ]_ about how to better implement a sentinel value for
54+ [1 ]_ about how to better implement a sentinel value for
5555``traceback.print_exception ``. The existing implementation used the
5656following common idiom::
5757
@@ -76,17 +76,16 @@ in the discussion:
7676 instance being created and thus comparisons using ``is `` failing
7777
7878In the ensuing discussion, Victor Stinner supplied a list of currently used
79- sentinel values in the Python standard library
80- [#list-of-sentinels-in-stdlib ]_. This showed that the need for sentinels is
81- fairly common, that there are various implementation methods used even
82- within the stdlib, and that many of these suffer from at least one of the
83- three aforementioned drawbacks.
79+ sentinel values in the Python standard library [2 ]_. This showed that the
80+ need for sentinels is fairly common, that there are various implementation
81+ methods used even within the stdlib, and that many of these suffer from at
82+ least one of the three aforementioned drawbacks.
8483
8584The discussion did not lead to any clear consensus on whether a standard
8685implementation method is needed or desirable, whether the drawbacks mentioned
8786are significant, nor which kind of implementation would be good.
8887
89- A poll was created on discuss.python.org [ #poll ]_ to get a clearer sense of
88+ A poll [ 3 ]_ was created on discuss.python.org to get a clearer sense of
9089the community's opinions. The poll's results were not conclusive, with 40%
9190voting for "The status-quo is fine / there’s no need for consistency in
9291this", but most voters voting for one or more standardized solutions.
@@ -151,7 +150,7 @@ be used rather than boolean checks such as ``if value:`` or ``if not value:``.
151150Sentinel instances are truthy by default.
152151
153152The names of sentinels are unique within each module. When calling
154- ``Sentinel()``in a module where a sentinel with that name was already
153+ ``Sentinel() `` in a module where a sentinel with that name was already
155154defined, the existing sentinel with that name will be returned. Sentinels
156155with the same name in different modules will be distinct from each other.
157156
@@ -168,20 +167,19 @@ as ``Sentinel()`` will usually be able to recognize the module in which it was
168167called. ``module_name `` should be supplied only in unusual cases when this
169168automatic recognition does not work as intended, such as perhaps when using
170169Jython or IronPython. This parallels the designs of ``Enum `` and
171- ``namedtuple ``. For more details, see `PEP 435 `_.
170+ ``namedtuple ``. For more details, see
171+ `PEP 435 <https://peps.python.org/pep-0435/#functional-api >`_.
172172
173173The ``Sentinel `` class may be sub-classed. Instances of each sub-class will
174174be unique, even if using the same name and module. This allows for
175175customizing the behavior of sentinels, such as controlling their truthiness.
176176
177- .. _PEP 435 : https://peps.python.org/pep-0435/#functional-api
178-
179177
180178Reference Implementation
181179========================
182180
183- The reference implementation is found in a dedicated GitHub repo
184- [ #reference-github-repo ]_. A simplified version follows::
181+ The reference implementation is found in a dedicated GitHub repo [ 4 ]_. A
182+ simplified version follows::
185183
186184 _registry = {}
187185
@@ -236,7 +234,7 @@ This suffers from all of the drawbacks mentioned in the `Rationale`_ section.
236234
237235
238236Add a single new sentinel value, such as ``MISSING `` or ``Sentinel ``
239- -----------------------------------------------------------------
237+ --------------------------------------------------------------------
240238
241239Since such a value could be used for various things in various places, one
242240could not always be confident that it would never be a valid value in some use
@@ -246,7 +244,7 @@ with confidence without needing to consider potential edge-cases.
246244Additionally, it is useful to be able to provide a meaningful name and repr
247245for a sentinel value, specific to the context where it is used.
248246
249- Finally, this was a very unpopular option in the poll [#poll ]_, with only 12%
247+ Finally, this was a very unpopular option in the poll [3 ]_, with only 12%
250248of the votes voting for it.
251249
252250
@@ -274,8 +272,8 @@ Besides the excessive repetition, the repr is overly long:
274272``<NotGivenType.NotGiven: 'NotGiven'> ``. A shorter repr can be defined, at
275273the expense of a bit more code and yet more repetition.
276274
277- Finally, this option was the least popular among the nine options in the poll
278- [ # poll ]_, being the only option to receive no votes.
275+ Finally, this option was the least popular among the nine options in the
276+ poll [ 3 ]_, being the only option to receive no votes.
279277
280278
281279A sentinel class decorator
@@ -322,7 +320,7 @@ Define a recommended "standard" idiom, without supplying an implementation
322320Most common exiting idioms have significant drawbacks. So far, no idiom
323321has been found that is clear and concise while avoiding these drawbacks.
324322
325- Also, in the poll on this subject [ #poll ]_ , the options for recommending an
323+ Also, in the poll [ 3 ]_ on this subject, the options for recommending an
326324idiom were unpopular, with the highest-voted option being voted for by only
32732525% of the voters.
328326
@@ -331,7 +329,7 @@ Additional Notes
331329================
332330
333331* This PEP and the initial implementation are drafted in a dedicated GitHub
334- repo [#reference-github-repo ]_.
332+ repo [4 ]_.
335333
336334* For sentinels defined in a class scope, to avoid potential name clashes,
337335 one should use the fully-qualified name of the variable in the module. Only
@@ -352,10 +350,10 @@ Additional Notes
352350References
353351==========
354352
355- .. [
#python-dev-thread ]
Python-Dev mailing list: `The repr of a sentinel <https://mail.python.org/archives/list/[email protected] /thread/ZLVPD2OISI7M4POMTR2FCQTE6TPMPTO3/ >`_ 356- .. [
#list-of-sentinels-in-stdlib ]
Python-Dev mailing list: `"The stdlib contains tons of sentinels" <https://mail.python.org/archives/list/[email protected] /message/JBYXQH3NV3YBF7P2HLHB5CD6V3GVTY55/ >`_ 357- .. [#poll ] discuss.python.org Poll: `Sentinel Values in the Stdlib <https://discuss.python.org/t/sentinel-values-in-the-stdlib/8810/ >`_
358- .. [#reference-github-repo ] `Reference implementation at the taleinat/python-stdlib-sentinels GitHub repo <https://github.com/taleinat/python-stdlib-sentinels >`_
353+ .. [
1 ]
Python-Dev mailing list: `The repr of a sentinel <https://mail.python.org/archives/list/[email protected] /thread/ZLVPD2OISI7M4POMTR2FCQTE6TPMPTO3/ >`_ 354+ .. [
2 ]
Python-Dev mailing list: `"The stdlib contains tons of sentinels" <https://mail.python.org/archives/list/[email protected] /message/JBYXQH3NV3YBF7P2HLHB5CD6V3GVTY55/ >`_ 355+ .. [3 ] discuss.python.org Poll: `Sentinel Values in the Stdlib <https://discuss.python.org/t/sentinel-values-in-the-stdlib/8810/ >`_
356+ .. [4 ] `Reference implementation at the taleinat/python-stdlib-sentinels GitHub repo <https://github.com/taleinat/python-stdlib-sentinels >`_
359357 .. [5 ] `bpo-44123: Make function parameter sentinel values true singletons <https://bugs.python.org/issue44123 >`_
360358 .. [6 ] `The "sentinels" package on PyPI <https://pypi.org/project/sentinels/ >`_
361359 .. [7 ] `The "sentinel" package on PyPI <https://pypi.org/project/sentinel/ >`_
0 commit comments