-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for detecting the flavour of pathlib subclasses #100502
Comments
This instance attribute stores the implementation of `os.path` used for low-level path operations: either `posixpath` or `ntpath`. The `PurePath` and `Path` initialisers gain a *flavour* keyword-only argument that sets the flavour. This argument is not available in the Posix- and Windows-specific subclasses, and as the `PurePath` and `Path` classes are not directly instantiable, it is available therefore only in user subclasses of `PurePath and `Path`. Such subclasses may determine their flavour in `__init__()` and supply the flavour to `super()`.
This instance attribute stores the implementation of `os.path` used for low-level path operations: either `posixpath` or `ntpath`. The `PurePath` and `Path` initialisers gain a *flavour* keyword-only argument that sets the flavour. This argument is not available in the Posix- and Windows-specific subclasses, and as the `PurePath` and `Path` classes are not directly instantiable, it is available therefore only in user subclasses of `PurePath and `Path`. Such subclasses may determine their flavour in `__init__()` and supply the flavour to `super()`.
This instance attribute stores the implementation of `os.path` used for low-level path operations: either `posixpath` or `ntpath`. The `PurePath` and `Path` initialisers gain a *flavour* keyword-only argument. This argument is not available in the Posix- and Windows-specific subclasses, and as the `PurePath` and `Path` classes are not directly instantiable, it is available therefore only in user subclasses of `PurePath` and `Path`. Such subclasses may determine their flavour in `__init__()` and supply the flavour to `super()`.
|
About |
Thanks for the feedback! Agree also on |
This instance attribute stores the implementation of `os.path` used for low-level path operations: either `posixpath` or `ntpath`.
@merwok I'm beginning to have doubts about the solution I implemented. I think the new, internal |
Would you revert to |
I think I'd keep the new name and mark it as private with |
This is related to the ongoing discussions about preserving final slash and follow_symlinks (and co) as implicit parameters, yes? Generally I trust you to shepherd the changes needed to support important features. If you still think the attribute should hidden now, then go ahead! |
…thonGH-106533)" This reverts commit c6c5665.
It's related to those discussions, but more directly to the work on pathlib ABCs which has been going on at the same time. There's now a private
Yes that's right. Thanks for the advice - I'll follow your suggestion to not revert yet. I appreciate your take on this :) |
I've played with two approaches:
Both of these have the effect of making Re-resolving this issue. |
Feature or enhancement
Provide a way of checking whether a user subclass of
pathlib.PurePath
andPath
uses POSIX or Windows semanticsThe Problem
Now that #68320 is resolved, users can subclass
pathlib.PurePath
andPath
directly:However, there's no (public) procedure to detect whether an instance of
MyPath
uses POSIX or Windows semantics.A non-public way of doing it:
Note that checking
isinstance(path, PurePosixPath)
(etc) won't work, as user subclasses ofPurePath
andPath
do not have the POSIX- and Windows-specific subclasses in their class hierarchy.The Proposal
Make the
_flavour
attribute public; document it. Possible names:flavour
(simply remove the underscore)pathmod
(used internally in older pathlib versions)module
(used in the longstanding thirdpartypath
package)Alternatives
We could make the
PurePosixPath
andPureWindowsPath
classes 'protocols', which supportisinstance()
checks even when the passed object isn't a conventional subclass. But:PurePosixPath
andPureWindowsPath
should be proper protocols, and not directly instantiable.A further alternative would be to add an
is_posix()
method, which gels pretty nicely with the existingis_*()
andas_posix()
methods.Linked PRs
pathlib.PurePath.pathmod
attribute #106533The text was updated successfully, but these errors were encountered: