Skip to content

Commit 9fa60eb

Browse files
committed
Add some notes on OS differences
1 parent 68c6533 commit 9fa60eb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Doc/library/os.path.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ the :mod:`glob` module.)
354354
is raised. If *strict* is ``False``, the path is resolved as far as possible
355355
and any remainder is appended without checking whether it exists.
356356

357+
.. note::
358+
This function emulates the operating system's procedure for making a path
359+
canonical, which differs slightly between Windows and UNIX with respect
360+
to how links and subsequent path components interact.
361+
362+
Operating system APIs make paths canonical as needed, so it's not
363+
normally necessary to call this function.
364+
357365
.. versionchanged:: 3.6
358366
Accepts a :term:`path-like object`.
359367

Lib/test/test_ntpath.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ def test_realpath_symlink_loops(self):
368368
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1")
369369
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2")
370370
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x")
371+
372+
# Windows eliminates '..' components before resolving links, so the
373+
# following 3 realpath() calls are not expected to raise.
371374
self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\.."),
372375
ntpath.dirname(ABSTFN))
373376
self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\x"),

0 commit comments

Comments
 (0)