# Pathlib: preserve trailing slash

**URL:** <https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389>\
**Category:** Ideas\
**Created:** [September 9, 2023, 4:44pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389 "2023-09-09T16:44:32Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [September 9, 2023, 4:44pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/1 "2023-09-09T16:44:32Z")

</div>

I find this issue intimidating:

> <https://github.com/python/cpython/issues/65238>
>
> BPO | \[21039\](https://bugs.python.org/issue21039)
> \--- | :---
> Nosy | @akuchling…, @pitrou, @serhiy-storchaka, @sigmavirus24, @hvenev
> Files | \<li\>\[pathlib.patch\](https://bugs.python.org/file34586/pathlib.patch "Uploaded as text/plain at 2014-03-23.13:55:55 by @hvenev"): patch\</li\>
> 
> \<sup\>\*Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.\*\</sup\>
> 
> \<details\>\<summary\>Show more details\</summary\>\<p\>
> 
> GitHub fields:
> \`\`\`python
> assignee = None
> closed\_at = \<Date 2015-04-14.16:54:25.933\>
> created\_at = \<Date 2014-03-23.13:55:56.401\>
> labels = \['type-bug', 'library'\]
> title = 'pathlib strips trailing slash'
> updated\_at = \<Date 2015-04-14.16:54:25.932\>
> user = 'https://github.com/hvenev'
> \`\`\`
> 
> bugs.python.org fields:
> \`\`\`python
> activity = \<Date 2015-04-14.16:54:25.932\>
> actor = 'pitrou'
> assignee = 'none'
> closed = True
> closed\_date = \<Date 2015-04-14.16:54:25.933\>
> closer = 'pitrou'
> components = \['Library (Lib)'\]
> creation = \<Date 2014-03-23.13:55:56.401\>
> creator = 'h.venev'
> dependencies = \[\]
> files = \['34586'\]
> hgrepos = \[\]
> issue\_num = 21039
> keywords = \['patch'\]
> message\_count = 15.0
> messages = \['214581', '214594', '214595', '214596', '214597', '214598', '214599', '214600', '214601', '214604', '224889', '224942', '240930', '240947', '240948'\]
> nosy\_count = 7.0
> nosy\_names = \['akuchling', 'pitrou', 'BreamoreBoy', 'serhiy.storchaka', 'icordasc', 'h.venev', 'ischwabacher'\]
> pr\_nums = \[\]
> priority = 'normal'
> resolution = 'wont fix'
> stage = None
> status = 'closed'
> superseder = None
> type = 'behavior'
> url = 'https://bugs.python.org/issue21039'
> versions = \['Python 3.4', 'Python 3.5'\]
> \`\`\`
> 
> \</p\>\</details\>
> 
> \### Blocks issues
> 
> \- #64978
> \- #73991
> \- #102783
> \- #106747
> 
> 
> \### Linked PRs
> \* gh-103595
> \* gh-112363

It seems to me that we _should_ solve it, as trailing slashes are meaningful to path resolution. Quoting `man path_resolution` on my local system:

> If a pathname ends in a ‘/’, that forces resolution of the preceding component as in Step 2: it has to exist and resolve to a directory. Otherwise, a trailing ‘/’ is ignored. (Or, equivalently, a pathname with a trailing ‘/’ is equivalent to the pathname obtained by appending ‘.’ to it.)

And POSIX 4.12:

> A pathname that contains at least one non-slash character and that ends with one or more trailing slash characters shall not be resolved successfully unless the last pathname component before the trailing slash characters names an existing directory or a directory entry that is to be created for a directory immediately after the pathname is resolved.

The fact that pathlib strips the trailing slash flies in the face of its otherwise conservative normalisation rules – for example, `pathlib.Path.absolute()` will not remove `..` segments, whereas `os.path.abspath()` _does_ remove these segments, which might change the meaning of a path.

I’m not sure how to fix the issue. My current thinking is to add a `keep_trailing_sep` argument to the `PurePath` and `Path` initialisers. Perhaps it could be `None` by default, which would raise a deprecation warning but otherwise act like `False`. In a future version of Python, we could then change the default to `True`.

Would that be worthwhile, or is it too disruptive? Any better ideas? Thanks

---

<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:** [September 9, 2023, 4:54pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/2 "2023-09-09T16:54:28Z")

</div>

As an alternative to the `keep_trailing_sep` idea, we could instead emit a warning when a path with a trailing slash is given to `PurePath()` or `Path()`, and after a couple of versions, remove the warning and begin preserving the trailing slash.

---

<div class="post-metadata">

**Author:** ![AA-Turner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aa-turner/32/4979_2.png) [@AA-Turner](https://discuss.python.org/u/AA-Turner)\
**Post date:** [September 9, 2023, 5:10pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/3 "2023-09-09T17:10:15Z")

</div>

To ask a naïve question, what would break if we switched immediately to preserving any trailing slashes?

A

---

<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:** [September 9, 2023, 5:28pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/4 "2023-09-09T17:28:29Z")

</div>

Two things in the standard library:

An `importlib.metadata.PathDistribution` object may point to an egg-info file rather than a directory. It’s `read_text()` method accepts a filename, which may set to the empty string. The method calls `joinpath()` to join these:

> <https://github.com/python/cpython/blob/main/Lib/importlib/metadata/ __init__.py#L809-L817>

If we preserve trailing slashes, this method adds a trailing slash to the `egg-info` file path (via `joinpath('')`), which makes it impossible to open as a file.

And `zipfile.Path` actually relies on pathlib to strip trailing slashes (which it otherwise uses to indicate directories):

> <https://github.com/python/cpython/blob/75cd86599bad05cb372aed9fccc3ff884cd38b70/Lib/zipfile/_path/ __init__.py#L300-L305>

The `zipfile.Path` bit _could_ be resolved in future by making it a subclass of the upcoming `pathlib.PathBase` class.

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [September 9, 2023, 5:35pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/5 "2023-09-09T17:35:04Z")

</div>

> [@AA-Turner](#):
>
> To ask a naïve question, what would break if we switched immediately to preserving any trailing slashes?

I suspect a lot of code will break. This would be a change in semantics that is backwards compatible. It would have to be opt in.

For example what would `name` return if there is a trailing pathsep?

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [September 9, 2023, 5:37pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/6 "2023-09-09T17:37:23Z")

</div>

> [@barneygale](#):
>
> And POSIX 4.12:
> 
> > A pathname that contains at least one non-slash character and that ends with one or more trailing slash characters shall not be resolved successfully unless the last pathname component before the trailing slash characters names an existing directory or a directory entry that is to be created for a directory immediately after the pathname is resolved.

What POSIX API does this rule apply to? Taken out of context I do not know what means.

---

<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:** [September 9, 2023, 5:38pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/7 "2023-09-09T17:38:08Z")

</div>

> [@barry-scott](#):
>
> For example what would `name` return if there is a trailing pathsep?

I _think_ it should return the empty string, similarly to `PosixPath('/').name` or `WindowsPath('C:/').name`. This allows the following idiom to be used to remove any trailing slash:

```python
if not path.name:
    path = path.parent

```

---

<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:** [September 9, 2023, 5:40pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/8 "2023-09-09T17:40:55Z")

</div>

> [@barry-scott](#):
>
> What POSIX API does this rule apply to? Taken out of context I do not know what means.

I should have provided a link, and not misquoted the section number. It’s in the “general concepts” chapter:

[https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1\_chap04.html#tag\_04\_13](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13)

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/guido/32/21_2.png) [@guido](https://discuss.python.org/u/guido)\
**Post date:** [September 9, 2023, 6:50pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/9 "2023-09-09T18:50:27Z")

</div>

(Cross-posted to GitHub: [pathlib strips trailing slash · Issue #65238 · python/cpython · GitHub](https://github.com/python/cpython/issues/65238#issuecomment-1712577347))

I’m sorry Antoine chose to let `pathlib` deviate from the `os.path` module’s behavior for this. I recall thinking long and hard about edge cases like this and carefully implementing what I thought was best. I haven’t read that POSIX standard but I presume I was influenced by actual behavior of various UNIX utilities.

But I agree that changing this will break plenty of user code relying on the current behavior, and we can’t have that. I also don’t think that some kind of deprecation path makes sense here. The best we can do is have some way to indicate the preferred behavior when a path is created, and have that inherited by operations that return new paths.

I’m not sure what form the user preference should take – I’d say it shouldn’t be global, so it could take the form of either an alternative class, an alternative constructor, or a flag keyword argument to path-constructing operations.

Even so, there could be problems – suppose we have a library that accepts `Path` arguments and expects them to behave the old way, and a user constructs paths using the alternate constructor and passes those in. It might be quite a while before the user ends up passing a path that causes the library to crash or misbehave.

So maybe an alternative approach could be not to have the behavior be indicated by some property of the `Path` instance but by using different attributes. So maybe e.g. `Path("foo/").name` would return `"foo"` but `Path("foo/").alt_name` would return `""`. This would avoid the scenario I described just above.

Now we just have to decide on names for the attributes that could have this alternate behavior (are there others besides `.parent` and `.name`?). And probably the implementation will have to keep track of the trailing slash somehow.

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.python.org/u/ali)\
**Post date:** [September 9, 2023, 7:25pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/10 "2023-09-09T19:25:43Z")

</div>

> [@guido](#):
>
> Now we just have to decide on names for the attributes that could have this alternate behavior (are there others besides `.parent` and `.name`?). And probably the implementation will have to keep track of the trailing slash somehow.

`tail` looks like a good name candidate for `.name`. The term is already used by the [`os.path.split` docs](https://docs.python.org/3/library/os.path.html#os.path.split) to mean exactly what is expected here. `head` could also be the alternative name to `.parent` with the new semantics.

---

<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:** [September 9, 2023, 7:37pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/11 "2023-09-09T19:37:47Z")

</div>

I think there are too many affected methods for that to work. For example, most methods defined in `Path` are affected by this bug:

```python
>>> import pathlib, os
>>> pathlib.Path('/etc/hosts/').stat()
os.stat_result(st_mode=33188, st_ino=82182074, st_dev=16777233, st_nlink=1, st_uid=0, st_gid=0, st_size=213, st_atime=1690969486, st_mtime=1690969486, st_ctime=1692390716)
>>> os.stat('/etc/hosts/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotADirectoryError: [Errno 20] Not a directory: '/etc/hosts/'

```

There’s also ` __str__ ()` and ` __fspath__ ()`.

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/guido/32/21_2.png) [@guido](https://discuss.python.org/u/guido)\
**Post date:** [September 9, 2023, 9:04pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/12 "2023-09-09T21:04:52Z")

</div>

Ah. But those errors are legit, and I don’t mind getting those where we didn’t before. The trailing slash is only valid for directories (or when we don’t know).

I think —str— and —fspath— are also fine to change.

---

<div class="post-metadata">

**Author:** ![jeanas](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jeanas/32/8115_2.png) [@jeanas](https://discuss.python.org/u/jeanas)\
**Post date:** [September 9, 2023, 9:14pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/13 "2023-09-09T21:14:26Z")

</div>

I _like_ the current `pathlib` behavior. I use `pathlib` in preference to `os.path` because it allows me to think less about finicky details, such as whether a path I receive contains a trailing slash. I don’t want to be testing each function both with and without trailing slashes.

For example, I might write code like this:

```auto
import argparse
from pathlib import Path

p = argparse.ArgumentParser()
p.add_argument("path", type=Path)
args = p.parse_args()

print(f"Processing {args.path}/ ...")

```

If `pathlib` started to keep trailing slashes, `python myscript.py foo/` would start printing `Processing foo// ...`. I would have to check for trailing slashes in the input.

Another example: suppose I cache information on certain directories in a database, and I write a utility `update-info` that updates the cache. If I use raw paths, `update-info foo-directory/` could store info about `foo-directory/` but leave stale cache info for `foo-directory`. `pathlib` allows me to solve this problem very conveniently.

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [September 9, 2023, 9:23pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/14 "2023-09-09T21:23:32Z")

</div>

> [@barneygale](#):
>
> I should have provided a link, and not misquoted the section number. It’s in the “general concepts” chapter:
> 
> [General Concepts](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13)

Thanks for the link. Having read that section in full I am still none the wiser about where that rule for trailing / applies.  
Operations like open() or mkdir() do not need this rule for example.  
I wonder what specific API function implements the rule?

Without knowing which API is affected it will not be possible to test.  
I would like to write a test program that changes behaviour on the trailing / being present or absent on each OS to see it in action.

If this only changes command line utility behaviour the its not pathlib’s problem I would argue.

---

<div class="post-metadata">

**Author:** ![ofek](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ofek/32/1033_2.png) [@ofek](https://discuss.python.org/u/ofek)\
**Post date:** [September 9, 2023, 11:33pm UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/15 "2023-09-09T23:33:42Z")

</div>

I see a lot of talk about POSIX compatibility, which is nice I guess, but I wonder if someone could shed light on what Windows has to say about this topic?

---

<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:** [December 6, 2023, 12:27am UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/16 "2023-12-06T00:27:28Z")

</div>

Experimentally, the trailing slash on Windows seems to have the same effect (i.e. forcing resolution as a directory):

```python
>>> os.stat('c:/windows')
os.stat_result(st_mode=16895, st_ino=1407374883832841, st_dev=10709685299559133658, st_nlink=1, st_uid=0, st_gid=0, st_size=16384, st_atime=1701822404, st_mtime=1700700385, st_ctime=1575709424)
>>> os.stat('c:/windows/')
os.stat_result(st_mode=16895, st_ino=1407374883832841, st_dev=10709685299559133658, st_nlink=1, st_uid=0, st_gid=0, st_size=16384, st_atime=1701822404, st_mtime=1700700385, st_ctime=1575709424)
>>> os.stat('c:/windows/notepad.exe')
os.stat_result(st_mode=33279, st_ino=562949954686276, st_dev=10709685299559133658, st_nlink=3, st_uid=0, st_gid=0, st_size=201216, st_atime=1701822285, st_mtime=1700340994, st_ctime=1700340994)
>>> os.stat('c:/windows/notepad.exe/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'c:/windows/notepad.exe/'

```

---

<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:** [December 6, 2023, 12:41am UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/17 "2023-12-06T00:41:17Z")

</div>

I’ve been making a bit of progress towards addressing this problem. The key realisations:

1. (Per Guido’s earlier comment) everything related to splitting dirnames and basenames needs to work as it did before, e.g.
  - `Path('/foo/bar/').parent == Path('/foo')`
  - `Path('/foo/bar/').name == 'bar'`

2. Pathlib’s joining should deviate slightly from `os.path.join()` by ignoring empty segments, e.g. `Path('foo', '') == Path('foo')`, and not `Path('foo/')`

I believe these constraints ensure good backwards compatibility. I have a WIP patch here, if anyone’s interested:

> <https://github.com/python/cpython/pull/112363>
>
> Fix the last known case where pathlib can mangle the meaning of a path. This bri…ngs pathlib in line with \[\*IEEE Std 1003.1-2017\*\](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1\_chap04.html#tag\_04\_13), where trailing slashes are meaningful to path resolution and should not be discarded.
> 
> \## Changes
> 
> In several important respects, paths with trailing slashes behave differently to their slash-less counterparts:
> 
> \- Paths with and without trailing slashes compare unequal and generate different hash codes
> \- \`\_\_str\_\_()\`, \`\_\_fspath\_\_()\` and related representations include any trailing slash
> \- The \`.parts\` tuple includes a final empty part if a path ends in a slash
> \- \`glob()\` patterns ending with a slash will now generate results ending with a slash, matching \`glob.glob()\` behaviour
> \- \`match()\` now observes trailing slashes, and so its pattern language exactly matches that of \`glob()\`.
> 
> To manipulate a trailing slash, we add these new methods/properties:
> 
> \- \`has\_trailing\_sep\` - read-only boolean indicating whether a trailing slash is present
> \- \`with\_trailing\_sep()\` - returns a new path with a trailing slash present
> \- \`without\_trailing\_sep()\` - returns a new path with a trailing slash omitted
> 
> \## Backwards compatibility
> 
> Empty segments given to the \`PurePath\` initialiser do not generate new segments, so \`str(PurePath("foo", ""))\` results in \`"foo"\`, not \`"foo/"\`.
> 
> Methods concerned with dirnames and basenames ignore any trailing slash:
> 
> \- \`name\`, \`stem\`, \`suffix\` and \`suffixes\` retrieve the last \_non-empty\_ path segment, and so any trailing slash are ignored
> \- \`with\_name()\`, \`with\_stem()\` and \`with\_suffix()\` replace the last \_non-empty\_ path segment
> \- \`parent\` and \`parents\` ignore any trailing slash
> \- \`relative\_to()\` and \`is\_relative\_to()\` ignore any trailing slash in the \*other\* argument
> 
> \## Dependencies
> 
> \- \[x\] #112362
> \- \[x\] #112365
> \- \[\] #112676
> 
> \## Future work
> 
> Once this lands, we can take advantage of the fact that pathlib does not mangle paths. Thus:
> 
> \- We can make \`\_\_fspath\_\_()\` return an \_unnormalized\_ path for a tasty speed boost in many applications 
> - #102783
> \- We can call into \`pathlib\` from \`shutil\`, which means we can add methods like \`chown()\`, \`move()\` and \`rmtree()\` without code duplication
> - #64978
> - #73991
> 
> \---
> 
> 
> \* Issue: gh-65238

---

<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:** [December 17, 2023, 1:00am UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/18 "2023-12-17T01:00:16Z")

</div>

I’m unsure how trailing slashes should affect the [`PurePath.parts`](https://docs.python.org/3/library/pathlib.html#accessing-individual-parts) property. Any thoughts? Present behaviour:

```python
>>> PurePath('foo/bar/').parts
('foo', 'bar')
>>> PurePosixPath('/foo/bar/').parts
('/', 'foo', 'bar')
>>> PureWindowsPath('c:/foo/bar/').parts
('c:\\', 'foo', 'bar')

```

We could ignore any trailing slash (like now), but it would make `parts` lossy. As ` __reduce__ ()` is implemented using `parts`, we’d need to change its implementation so that trailing slashes survive pickling.

Or we could add an extra dot part on the end, like `('foo', 'bar', '.')`, or a separator to the final part, like `('foo', 'bar/')`. But that might break user code. Perhaps we do this in a new `full_parts` attribute?

Grateful for any guidance, cheers.

---

<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:** [December 17, 2023, 2:11am UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/19 "2023-12-17T02:11:17Z")

</div>

@pitrou would love to hear your view on the above ^

---

<div class="post-metadata">

**Author:** ![pitrou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pitrou/32/28_2.png) [@pitrou](https://discuss.python.org/u/pitrou)\
**Post date:** [December 17, 2023, 10:08am UTC](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389/20 "2023-12-17T10:08:38Z")

</div>

To me, the one question is: which use case needs trailing slashes to be significant in pathlib?

FTR, I don’t count “rigorous compliance with the POSIX specification” a use case 🙂 . The fact that `os.stat('/etc/hosts/')` raises an error doesn’t seem like a useful feature for day-to-day programming.

[Next page](https://discuss.python.org/t/pathlib-preserve-trailing-slash/33389.md?page=2)
