Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ the :mod:`glob` module.)

.. data:: ALL_BUT_LAST

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

.. versionadded:: 3.15

.. data:: ALLOW_MISSING

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

.. versionadded:: 3.15

Expand Down
22 changes: 5 additions & 17 deletions Lib/genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,8 @@ def _check_arg_types(funcname, *args):
raise TypeError("Can't mix strings and bytes in path components") from None


# Singletons with a true boolean value.

@object.__new__
class ALL_BUT_LAST:
"""Special value for use in realpath()."""
def __repr__(self):
return 'os.path.ALL_BUT_LAST'
def __reduce__(self):
return self.__class__.__name__

@object.__new__
class ALLOW_MISSING:
"""Special value for use in realpath()."""
def __repr__(self):
return 'os.path.ALLOW_MISSING'
def __reduce__(self):
return self.__class__.__name__
# Sentinels.
ALL_BUT_LAST = sentinel('ALL_BUT_LAST')
"""Special value for use in realpath()."""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it used as a docstring of the sentinel? I wonder, how can this be implemented?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentinels don't actually support docstrings. Putting a string like this is an established way to document a variable and I believe Sphinx supports it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then they are not needed.

ALLOW_MISSING = sentinel('ALLOW_MISSING')
"""Special value for use in realpath()."""
4 changes: 2 additions & 2 deletions Lib/test/test_genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ def test_realpath_mode_values(self):
for name in 'ALL_BUT_LAST', 'ALLOW_MISSING':
with self.subTest(name):
mode = getattr(self.pathmodule, name)
self.assertEqual(repr(mode), 'os.path.' + name)
self.assertEqual(str(mode), 'os.path.' + name)
self.assertEqual(repr(mode), name)
self.assertEqual(str(mode), name)
self.assertTrue(mode)
self.assertIs(copy.copy(mode), mode)
self.assertIs(copy.deepcopy(mode), mode)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:data:`os.path.ALLOW_MISSING` and :data:`os.path.ALL_BUT_LAST` are now
instances of :class:`sentinel`.
Loading