Repository navigation
Remove pathlib flavours #88302
Description
Activity
Following bpo-39899, bpo-43757 and bpo-43012,
pathlib._Flavourand its subclasses are looking a bit pointless.The implementations of
is_reserved()andmake_uri()(~as_uri()) can be readily moved to intoPurePosixPathandPureWindowsPath, which removes some indirection. This follows the pattern of OS-specific stuff inPosixPathandWindowsPath.The remaining methods, such as
splitroot(), can be pulled intoPure*Pathwith an underscore prefix.I'm generally a believer in composition over inheritance, but in this case
_Flavourseems too small and too similar toPurePathto separate out into 3 extra classes.There should be no impact on public APIs or performance.
- added3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 14, 2021 ^ just to bring my previous comment up-to-date:
I'm no longer pursuing adding
os.path.isreserved()andos.path.fileuri()functions, or modifyingnormpath(). At least, not for now!Instead, my plan is to move flavour functionality as follows (as classmethods with underscore prefixes):
_Flavour --> PurePath
_PosixFlavour --> PurePath
_WindowsFlavour --> PureWindowsPathAs a result, PurePath will use POSIX syntax by default. This is fully backwards-compatible, as users can't create PurePath objects! PurePath.__new__() instantiates PurePosixPath or PureWindowsPath. But it will matter for future user subclasses of PurePath/Path, where we usually want POSIX syntax.
I think there will be three PRs involved. PR 30320 and PR 30321 move _Flavour.make_uri() and _Flavour.is_reserved() respectively; these are reasonably standalone. If/when they land, I'll make a larger PR that moves the remaining methods into PurePath and PureWindowsPath.
- added a commit that references this issue
on Dec 28, 2022
pathlib._Flavour#26141os.path.fileuri()function. #26708_Flavour.make_uri()intoPurePath.as_uri()#30320_Flavour.is_reserved()intoPurePath.is_reserved()#30321pathlib.Pathsubclassing #31691Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: