Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
pathlib.PurePath.__reduce__() currently accesses and returnstheparts tuple. Pathlib ensures that the strings therein areinterned.
There's a good reason to do this: it ensures that the pickled data is as small as possible, with maximum re-use of small string objects.
However, it comes with some disadvantages:
- When normalising any path, we need to call
sys.intern(str(part))on each part - When pickling a path, we must join, parse and normalise, and then generate the
partstuple.
We could instead make__reduce__() return the raw paths fed to the constructor (the_raw_paths attribute). This would be faster but less space efficient. With the cost of storage and bandwidth falling at a faster rate than compute, I suspect this trade-off is worth making.