Skip to content

Commit dc1dcc0

Browse files
committed
Change proposed name of shutil.umask to shutil.umask_of
1 parent d53cf30 commit dc1dcc0

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Doc/library/shutil.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ High-level :term:`context managers <context manager>` for changing a process's e
892892
temporarily relinquished. Unless explicitly desired, you should not yield
893893
within these context managers.
894894

895-
.. class:: umask(mask)
895+
.. class:: umask_of(mask)
896896

897897
This is a simple wrapper around :func:`os.umask`. It changes the process's
898898
umask upon entering and restores the old one on exit.
@@ -901,13 +901,13 @@ High-level :term:`context managers <context manager>` for changing a process's e
901901

902902
.. versionadded:: next
903903

904-
In this example, we use a :class:`umask` context manager, within which we
904+
In this example, we use a :class:`umask_of` context manager, within which we
905905
create a file that only the user can access:
906906

907907
.. code-block:: pycon
908908
909-
>>> from shutil import umask
910-
>>> with umask(0o077):
909+
>>> from shutil import umask_of
910+
>>> with umask_of(0o077):
911911
... with open("my-secret-file", "w") as f:
912912
... f.write("I ate all the cake!\n")
913913
@@ -918,7 +918,7 @@ The file's permissions are empty for anyone but the user:
918918
$ ls -l my-secret-file
919919
-rw------- 1 guest guest 20 Jan 1 23:45 my-secret-file
920920
921-
Using :class:`umask` like this is better practice than first creating the file,
921+
Using :class:`umask_of` like this is better practice than first creating the file,
922922
and later changing its permissions with :func:`~os.chmod`, between which a
923923
period of time exists in which the file may have too lenient permissions.
924924

Lib/shutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"get_unpack_formats", "register_unpack_format",
6363
"unregister_unpack_format", "unpack_archive",
6464
"ignore_patterns", "chown", "which", "get_terminal_size",
65-
"SameFileError", "umask"]
65+
"SameFileError", "umask_of"]
6666
# disk_usage is added later, if available on the platform
6767

6868
class Error(OSError):
@@ -1583,7 +1583,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
15831583
return None
15841584

15851585

1586-
class umask(AbstractContextManager):
1586+
class umask_of(AbstractContextManager):
15871587
"""Non thread-safe context manager to change the process's umask."""
15881588

15891589
def __init__(self, mask):

Lib/test/test_shutil.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
get_archive_formats, Error, unpack_archive,
2222
register_unpack_format, RegistryError,
2323
unregister_unpack_format, get_unpack_formats,
24-
SameFileError, _GiveupOnFastCopy, umask)
24+
SameFileError, _GiveupOnFastCopy, umask_of)
2525
import tarfile
2626
import zipfile
2727
try:
@@ -3458,7 +3458,7 @@ def test_module_all_attribute(self):
34583458
'unregister_archive_format', 'get_unpack_formats',
34593459
'register_unpack_format', 'unregister_unpack_format',
34603460
'unpack_archive', 'ignore_patterns', 'chown', 'which',
3461-
'get_terminal_size', 'SameFileError', 'umask']
3461+
'get_terminal_size', 'SameFileError', 'umask_of']
34623462
if hasattr(os, 'statvfs') or os.name == 'nt':
34633463
target_api.append('disk_usage')
34643464
self.assertEqual(set(shutil.__all__), set(target_api))
@@ -3468,7 +3468,7 @@ def test_module_all_attribute(self):
34683468

34693469
@unittest.skipIf(os.name != "posix" or support.is_wasi or support.is_emscripten,
34703470
"need proper os.umask()")
3471-
class TestUmask(unittest.TestCase):
3471+
class TestUmaskOf(unittest.TestCase):
34723472
# make target masks in here sufficiently exotic, away from 0o022
34733473

34743474
mask_private = 0o777
@@ -3483,7 +3483,7 @@ def test_simple(self):
34833483
target_mask = self.mask_private
34843484
self.assertNotEqual(old_mask, target_mask)
34853485

3486-
with umask(target_mask):
3486+
with umask_of(target_mask):
34873487
self.assertEqual(self.get_mask(), target_mask)
34883488
self.assertEqual(self.get_mask(), old_mask)
34893489

@@ -3492,7 +3492,7 @@ def test_reentrant(self):
34923492
target_mask_1 = self.mask_private
34933493
target_mask_2 = self.mask_public
34943494
self.assertNotIn(old_mask, (target_mask_1, target_mask_2))
3495-
umask1, umask2 = umask(target_mask_1), umask(target_mask_2)
3495+
umask1, umask2 = umask_of(target_mask_1), umask_of(target_mask_2)
34963496

34973497
with umask1:
34983498
self.assertEqual(self.get_mask(), target_mask_1)
@@ -3510,7 +3510,7 @@ def test_exception(self):
35103510
self.assertNotEqual(old_mask, target_mask)
35113511

35123512
try:
3513-
with umask(target_mask):
3513+
with umask_of(target_mask):
35143514
self.assertEqual(self.get_mask(), target_mask)
35153515
raise RuntimeError("boom")
35163516
except RuntimeError as re:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Add a :class:`~shutil.umask` context manager to :mod:`shutil`, to provide a
1+
Add a :class:`~shutil.umask_of` context manager to :mod:`shutil`, to provide a
22
stdlib context manager for changing a process's umask

0 commit comments

Comments
 (0)