-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
I propose that we add a pathlib.PurePath.segments
attribute that stores the original arguments given to the PurePath
initializer. If we did this, then:
- Users would be able to implement their own
joinpath()
/__truediv__()
-like methods without resorting toPurePath.parts
(requires normalization - slow!) or the privatePurePath._raw_paths
attribute. - In the pathlib ABCs, we can make
JoinablePath.segments
abstract, and use it from a default implementation ofJoinablePath.__str__()
.- N.B.
JoinablePath.__str__()
is currently abstract, which is weird given it's non-abstract inobject
.
- N.B.
Usage would look like:
>>> p = PurePath('/usr', 'bin/python3')
>>> p.segments
('/usr', 'bin/python3')
When a PurePath
object is given as an argument, its segments should be merged:
>>> p = PurePath('/usr', PurePath('bin', 'python3'))
>>> p.segments
('/usr', 'bin', 'python3')
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
https://discuss.python.org/t/protocol-for-virtual-filesystem-paths/82753/8
Linked PRs
kfot
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement