diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-04-05 12:35:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 12:35:01 (GMT) |
commit | abfa16b44bb9426312613893b6e193b02ee0304f (patch) | |
tree | 1056d6152eb26836e630e4a5974f7e2201aea6a1 /Lib/test/test_posixpath.py | |
parent | 9ceaee74db7da0e71042ab0b385d844e9f282adb (diff) | |
download | cpython-abfa16b44bb9426312613893b6e193b02ee0304f.zip cpython-abfa16b44bb9426312613893b6e193b02ee0304f.tar.gz cpython-abfa16b44bb9426312613893b6e193b02ee0304f.tar.bz2 |
GH-114847: Speed up `posixpath.realpath()` (#114848)
Apply the following optimizations to `posixpath.realpath()`:
- Remove use of recursion
- Construct child paths directly rather than using `join()`
- Use `os.getcwd[b]()` rather than `abspath()`
- Use `startswith(sep)` rather than `isabs()`
- Use slicing rather than `split()`
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Lib/test/test_posixpath.py')
-rw-r--r-- | Lib/test/test_posixpath.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index cbb7c4c..807f985 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -458,6 +458,15 @@ class PosixPathTest(unittest.TestCase): @os_helper.skip_unless_symlink @skip_if_ABSTFN_contains_backslash + def test_realpath_missing_pardir(self): + try: + os.symlink(os_helper.TESTFN + "1", os_helper.TESTFN) + self.assertEqual(realpath("nonexistent/../" + os_helper.TESTFN), ABSTFN + "1") + finally: + os_helper.unlink(os_helper.TESTFN) + + @os_helper.skip_unless_symlink + @skip_if_ABSTFN_contains_backslash def test_realpath_symlink_loops(self): # Bug #930024, return the path unchanged if we get into an infinite # symlink loop in non-strict mode (default). |