# Make pathlib extensible

**URL:** <https://discuss.python.org/t/make-pathlib-extensible/3428>\
**Category:** Ideas\
**Created:** [February 24, 2020, 12:15am UTC](https://discuss.python.org/t/make-pathlib-extensible/3428 "2020-02-24T00:15:07Z")\
**Posts on this page:** 1\
**Showing post:** 77

<div class="post-metadata">

**Author:** ![barneygale](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/barneygale/32/1882_2.png) [@barneygale](https://discuss.python.org/u/barneygale)\
**Post date:** [February 19, 2023, 2:43pm UTC](https://discuss.python.org/t/make-pathlib-extensible/3428/77 "2023-02-19T14:43:41Z")

</div>

✨ February 2023 progress report ✨

[GH-101002](https://github.com/python/cpython/pull/101002) has landed, and so Python 3.12 has gained an [`os.path.splitroot()`](https://docs.python.org/3.12/library/os.path.html#os.path.splitroot) function, which can split a path into a tuple of `(drive, root, tail)`. Pathlib uses this function to efficiently parse paths according to OS-specific rules. Thanks again to Alex Waygood and Eryk Sun for their invaluable input, and respect to Antoine Pitrou for identifying the importance of three-part division when he created pathlib.

My plan now looks like this:

1. Address [GH-101362: Optimize pathlib path construction](https://github.com/python/cpython/issues/101362)
  - I’ve opened three PRs that make small individual improvements: [GH-101664](https://github.com/python/cpython/pull/101664), [GH-101665](https://github.com/python/cpython/pull/101665) and [GH-101667](https://github.com/python/cpython/pull/101667). I have one more of these on the way.
  - I’ll then open a larger PR that makes pathlib defer parsing/normalization until its needed

2. Address [GH-76846: `pathlib.Path._from_parsed_parts()` should call `cls. __new__ (cls)`](https://github.com/python/cpython/issues/76846) and [GH-85281: subclasses of `pathlib.PurePosixPath` never call ` __init__ ()` or ` __new__ ()`](https://github.com/python/cpython/issues/85281)
  - This will reduce performance of some pathlib operations, notably `iterdir()`, `glob()` and `walk()`.
  - I’m hoping to make this performance loss as small as possible through the optimisations in step #1.

3. Address [GH-100479: Support for sharing state between pathlib subclasses](https://github.com/python/cpython/issues/100479)
4. Add `pathlib.AbstractPath` 🥳

I’m also looking at issues and feature requests related to `glob()` – the largest category of pathlib issues on GitHub. There’s three lines of work that I think will converge:

- Make `glob()` treat symlinks consistently – see [GH-77609](https://github.com/python/cpython/issues/77609) for discussion
- @Ovsyanka’s fast iterative implementation of `walk()` – PR: [GH-100282](https://github.com/python/cpython/pull/100282)
- My fast regex-based implementation of `match()` – PR: [GH-101398](https://github.com/python/cpython/pull/101398)

With these in place, we can write a fast implementation of `glob()`, including a really chonky speedup for recursive globs. This should help relieve any lingering pain caused by the main plan (see step 2 above).

Thanks for reading! Bye for now

---

_[View the full topic](https://discuss.python.org/t/make-pathlib-extensible/3428)._
