diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index 51abe58410b..1c02e4168d3 100644 --- a/Lib/pathlib/_local.py +++ b/Lib/pathlib/_local.py @@ -272,8 +272,7 @@ class PurePath(PurePathBase): elif len(drv_parts) == 6: # e.g. //?/unc/server/share root = sep - parsed = [sys.intern(str(x)) for x in rel.split(sep) if x and x != '.'] - return drv, root, parsed + return drv, root, [x for x in rel.split(sep) if x and x != '.'] @property def _raw_path(self): diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index f4449b1a40d..b47b4a194cf 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -163,15 +163,6 @@ class PurePathTest(test_pathlib_abc.DummyPurePathTest): # Special case for the empty path. self._check_str('.', ('',)) - def test_parts_interning(self): - P = self.cls - p = P('/usr/bin/foo') - q = P('/usr/local/bin') - # 'usr' - self.assertIs(p.parts[1], q.parts[1]) - # 'bin' - self.assertIs(p.parts[2], q.parts[3]) - def test_join_nested(self): P = self.cls p = P('a/b').joinpath(P('c')) diff --git a/Misc/NEWS.d/next/Library/2024-08-26-18-48-13.gh-issue-119518.QFYH9q.rst b/Misc/NEWS.d/next/Library/2024-08-26-18-48-13.gh-issue-119518.QFYH9q.rst new file mode 100644 index 00000000000..819295f7306 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-08-26-18-48-13.gh-issue-119518.QFYH9q.rst @@ -0,0 +1,2 @@ +Speed up normalization of :class:`pathlib.PurePath` and +:class:`~pathlib.Path` objects by not interning string parts.