There are a few small adjustments we can make to pathlib path initialization and joining that improve performance:
- Ignore empty strings given to the initializer, which saves a
pathmod.join() call
- Store joined string in
self._raw_paths, which makes subsequent joining faster
- Handle empty paths without calling
_parse_path()
- Check for the common case (
len(self._raw_paths) == 1) first, and replace a length check with a truth check in the subsequent elif:
- Remove some unneeded local variables.
Linked PRs
There are a few small adjustments we can make to pathlib path initialization and joining that improve performance:
pathmod.join()callself._raw_paths, which makes subsequent joining faster_parse_path()len(self._raw_paths) == 1) first, and replace a length check with a truth check in the subsequentelif:Linked PRs
__init_subclass__()#113409