Antoine Pitrou  committed 855c0a5

Backport 87b81b7df7f0

  • Participants
  • Parent commits 5a9b487
  • Branches pep428

Comments (0)

Files changed (4)

 Version 1.0
+- Python issue #19921: When Path.mkdir() is called with parents=True, any
+  missing parent is created with the default permissions, ignoring the mode
+  argument (mimicking the POSIX "mkdir -p" command).
 - Python issue #19887: Improve the Path.resolve() algorithm to support
   certain symlink chains.
 - Make pathlib usable under Python 2.7 with unicode pathnames (only pure

File docs/index.rst

    and access flags.  If the path already exists, :exc:`OSError` is raised.
    If *parents* is true, any missing parents of this path are created
-   as needed.  If *parents* is false (the default), a missing parent raises
+   as needed; they are created with the default permissions without taking
+   *mode* into account (mimicking the POSIX ``mkdir -p`` command).
+   If *parents* is false (the default), a missing parent raises
             except OSError as e:
                 if e.errno != ENOENT:
-                self.parent.mkdir(mode, True)
+                self.parent.mkdir(parents=True)
                 self._accessor.mkdir(self, mode)
     def chmod(self, mode):


         with self.assertRaises(OSError) as cm:
         self.assertEqual(cm.exception.errno, errno.EEXIST)
-        # XXX test `mode` arg
     def test_mkdir_parents(self):
         # Creating a chain of directories
         with self.assertRaises(OSError) as cm:
         self.assertEqual(cm.exception.errno, errno.EEXIST)
-        # XXX test `mode` arg
+        # test `mode` arg
+        mode = stat.S_IMODE(p.stat().st_mode) # default mode
+        p = self.cls(BASE, 'newdirD', 'newdirE')
+        p.mkdir(0o555, parents=True)
+        self.assertTrue(p.exists())
+        self.assertTrue(p.is_dir())
+        if != 'nt':
+            # the directory's permissions follow the mode argument
+            self.assertEqual(stat.S_IMODE(p.stat().st_mode), 0o555 & mode)
+        # the parent's permissions follow the default process settings
+        self.assertEqual(stat.S_IMODE(p.parent.stat().st_mode), mode)
     def test_symlink_to(self):