GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-39659: Route calls from pathlib.Path to os.getcwd() via the path accessor by barneygale · Pull Request #18834 · python/cpython

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

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.

Sign up for GitHub

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

Merged
zooba merged 1 commit into python:master from barneygale:bpo-39659-pathlib-accessor-getcwd
Apr 7, 2021

Uh oh!

There was an error while loading. Please reload this page.

Merged

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

Changes from all commits
Commits
Show all changes
1 commit
Select commit
74abd98
bpo-39659: Route calls from pathlib.Path to os.getcwd() via the path …
barneygale Mar 8, 2020
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

10 changes: 6 additions & 4 deletions 10 Lib/pathlib.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def compile_pattern(self, pattern):
def resolve(self, path, strict=False):
s = str(path)
if not s:
return os.getcwd()
return path._accessor.getcwd()
previous_s = None
if _getfinalpathname is not None:
if strict:
Expand Down Expand Up @@ -352,7 +352,7 @@ def _resolve(path, rest):
return path
# NOTE: according to POSIX, getcwd() cannot contain path components
# which are symlinks.
base = '' if path.is_absolute() else os.getcwd()
base = '' if path.is_absolute() else accessor.getcwd()
return _resolve(base, str(path)) or sep

def is_reserved(self, parts):
Expand Down Expand Up @@ -469,6 +469,8 @@ def group(self, path):
except ImportError:
raise NotImplementedError("Path.group() is unsupported on this system")

getcwd = os.getcwd


_normal_accessor = _NormalAccessor()

Expand Down Expand Up @@ -1104,7 +1106,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())
Comment thread Outdated

@pitrou pitrou Apr 17, 2020

Copy link
Copy Markdown
Member

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.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@barneygale barneygale May 29, 2020

Copy link
Copy Markdown
Contributor Author

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@barneygale barneygale Jan 22, 2021

Copy link
Copy Markdown
Contributor Author

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@barneygale barneygale Jan 22, 2021

Copy link
Copy Markdown
Contributor Author

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.

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

  • _accessor is set in _init(), at least until bpo-40038: pathlib: remove partial support for preserving accessor when modifying a path #19342 lands
  • _flavour is set in __new__().

Reverting to previous patch (the one you reviewed).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@classmethod
def home(cls):
Expand Down Expand Up @@ -1173,7 +1175,7 @@ def absolute(self):
return self
# FIXME this must defer to the specific flavour (and, under Windows,
# use nt._getfullpathname())
return self._from_parts([os.getcwd()] + self._parts)
return self._from_parts([self._accessor.getcwd()] + self._parts)

def resolve(self, strict=False):
"""
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.