Skip to content

Commit 20b62f7

Browse files
committed
gh-149083: Use sentinel for os.path.{ALLOW_MISSING,ALL_BUT_LAST}
1 parent 7241f27 commit 20b62f7

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

Doc/library/os.path.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,13 @@ the :mod:`glob` module.)
482482

483483
.. data:: ALL_BUT_LAST
484484

485-
Special value used for the *strict* argument in :func:`realpath`.
485+
:class:`sentinel` used for the *strict* argument in :func:`realpath`.
486486

487487
.. versionadded:: 3.15
488488

489489
.. data:: ALLOW_MISSING
490490

491-
Special value used for the *strict* argument in :func:`realpath`.
491+
:class:`sentinel` used for the *strict* argument in :func:`realpath`.
492492

493493
.. versionadded:: 3.15
494494

Lib/genericpath.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,8 @@ def _check_arg_types(funcname, *args):
201201
raise TypeError("Can't mix strings and bytes in path components") from None
202202

203203

204-
# Singletons with a true boolean value.
205-
206-
@object.__new__
207-
class ALL_BUT_LAST:
208-
"""Special value for use in realpath()."""
209-
def __repr__(self):
210-
return 'os.path.ALL_BUT_LAST'
211-
def __reduce__(self):
212-
return self.__class__.__name__
213-
214-
@object.__new__
215-
class ALLOW_MISSING:
216-
"""Special value for use in realpath()."""
217-
def __repr__(self):
218-
return 'os.path.ALLOW_MISSING'
219-
def __reduce__(self):
220-
return self.__class__.__name__
204+
# Sentinels.
205+
ALL_BUT_LAST = sentinel('ALL_BUT_LAST')
206+
"""Special value for use in realpath()."""
207+
ALLOW_MISSING = sentinel('ALLOW_MISSING')
208+
"""Special value for use in realpath()."""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:data:`os.path.ALLOW_MISSING` and :data:`os.path.ALL_BUT_LAST` are now
2+
instances of :class:`sentinel`.

0 commit comments

Comments
 (0)