Skip to content
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

bpo-39659: Route calls from pathlib.Path to os.getcwd() via the path accessor #18834

Merged
merged 1 commit into from
Apr 7, 2021

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Mar 8, 2020

(from the bug description:) Whereas most calls to os functions from pathlib.Path methods happen via pathlib._Accessor methods, retrieving the current working directory does not. This problem occurs when calling the pathlib.Path.cwd(), ~resolve() and ~absolute() methods.

https://bugs.python.org/issue39659

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@barneygale

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@barneygale
Copy link
Contributor Author

This change should have no functional effect beyond the addition of pathlib._NormalAccessor.getcwd(). which is an internal API anyway. The idea is to make the "accessor" abstraction less leaky and perhaps work our way towards a more extensible pathlib (see here)

@@ -1099,7 +1101,7 @@ def cwd(cls):
"""Return a new path pointing to the current working directory
(as returned by os.getcwd()).
"""
return cls(os.getcwd())
return cls(cls()._accessor.getcwd())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a quirky way to implement it. If the accessor becomes tied to the class rather than specific instances, perhaps it should become a class-level attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very similar to how home() is implemented immediately below.

Agree generally that the accessor should be a class attribute and not an instance attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced cls() with cls in this method, and home() for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that didn't work at all! Looks like:

Reverting to previous patch (the one you reviewed).

@barneygale barneygale force-pushed the bpo-39659-pathlib-accessor-getcwd branch 3 times, most recently from cfc20dc to 05e73d0 Compare January 22, 2021 01:51
@zooba
Copy link
Member

zooba commented Apr 7, 2021

@barneygale This one looks like the conflict is meaningful? (And it's new because I merged one of your other changes, I think)

@barneygale barneygale force-pushed the bpo-39659-pathlib-accessor-getcwd branch from 05e73d0 to 74abd98 Compare April 7, 2021 00:59
@barneygale
Copy link
Contributor Author

Thank you! Rebased :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants