gh-101357: use `os.path.exists()` etc from pathlib by barneygale · Pull Request #101361 · python/cpython · GitHub
Skip to content

gh-101357: use os.path.exists() etc from pathlib - #101361

Closed
barneygale wants to merge 1 commit into
python:mainfrom
barneygale:gh-101357-fast-is-file-etc
Closed

gh-101357: use os.path.exists() etc from pathlib#101361
barneygale wants to merge 1 commit into
python:mainfrom
barneygale:gh-101357-fast-is-file-etc

Conversation

@barneygale

@barneygale barneygale commented Jan 27, 2023

Copy link
Copy Markdown
Contributor

The following pathlib.Path methods now directly call functions in os.path:

  • samefile()
  • exists()
  • is_dir()
  • is_file()
  • is_symlink()

In conjunction with #101324, this improves performance of these methods by using making fewer system calls than stat()

The original generic implementations of these methods are preserved in a new, internal _PathWithStat class. In future this may form the basis of a public AbstractPath class. The generic implementation of is_mount(), which was removed in 29650fea, is also restored to this class.


The following `pathlib.Path` methods now directly call functions in
`os.path`:

- `samefile()`
- `exists()`
- `is_dir()`
- `is_file()`
- `is_symlink()`

In conjunction with python#101324, this improves performance of these methods
by using making fewer system calls than `stat()`

The original generic implementations of these methods are preserved in a
new, internal `_PathWithStat` class. In future this may form the basis of
a public `AbstractPath` class. The generic implementation of `is_mount()`,
which was removed in 29650fea, is also restored to this class.
@mdboom

mdboom commented Feb 8, 2023

Copy link
Copy Markdown
Contributor

@barneygale

Copy link
Copy Markdown
Contributor Author

since a new kwarg would be an API change that we probably want to avoid

We added a similar strict keyword-only argument to os.path.realpath() recently - couldn't we do that here too?

@barneygale

Copy link
Copy Markdown
Contributor Author

@barneygale barneygale closed this Feb 20, 2023
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.

3 participants