-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
Simplified Path declarations #2246
Conversation
So ... it was intentional, for two reasons:
(1) is a relatively minor cosmetic detail; but (2) is more substantial. I was under the impression that using an explicit However, if that's not the case, and you can provide documented evidence that the forward-slash handling in Path objects is intentionally cross-platform, then I don't object to collapsing the paths to a simpler "single string" form where it clearly improves readability. |
I'm pretty certain that treating Oddly enough, looking now I see that this isn't explicitly claimed in the docs, but it is demonstrated by the examples, for instance:
p = PurePath('/etc')
str(p)
'/etc'
p = PureWindowsPath('c:/Program Files')
str(p)
'c:\\Program Files' Many other examples there show creation of Windows paths using forward slashes. (Rest in peace, os.path.join. Please don't come back.) |
Not sure if a more-explicit-but-less-authoritative source is relevant, but Trey Hunner talks about it in the second of his pair of pathlib-prozelytizing posts that I liked sharing around, especially when pathlib was quite new and many hadn't used it yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The combination of a weak docs reference, Trey's opinion, and a test suite passing on Windows is enough to convince me. Thanks for the cleanup!
Thanks for doing this – if you feel ambitious, you could try doing the same in Briefcase. 😄 |
This might very well be a solution for a non-problem, but I noticed that a lot of paths in the codebase are written with all slash operators, like this:
All this PR does is simplify all such instances , e.g.:
This avoids creating and discarding intermediate Path objects along the way, and at least personally I find it more readable too.
In the event that this is an intentional style decision, I could submit a PR that instead changes all of the latter style to the former, for consistency.
PR Checklist: