Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-125413: Addpathlib.Path.info attribute#127730

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
barneygale merged 43 commits intopython:mainfrombarneygale:gh-125413-info
Feb 8, 2025

Conversation

barneygale
Copy link
Contributor

@barneygalebarneygale commentedDec 7, 2024
edited
Loading

Addpathlib.Path.info attribute, which stores an object implementing thepathlib.types.PathInfo protocol (also new). The object supports querying the file type and internally cachingos.stat() results. Path objects generated byPath.iterdir() are initialised with status information fromos.DirEntry objects, which is gleaned from scanning the parent directory.

ThePathInfo protocol has four methods:exists(),is_dir(),is_file() andis_symlink().

When a path object is generated by `PathBase.iterdir()`, then its `_info`attribute now stores a `os.DirEntry`-like object that can be used to querythe file type. This removes any need for a `_scandir()` method.Currently the `_info` attribute is private and only guaranteed to bepopulated in paths from `iterdir()`. Later on, I'm hoping to rename it to`info` and ensure that it's populated for all kinds of paths (this probablyinvolves adding a `pathlib.FileInfo` class.) In the pathlib ABCs, `info`will replace `stat()` as the lowest-level abstract file status queryingmechanism.
@barneygale
Copy link
ContributorAuthor

Steve - hopefully this helps address the issues you raised in#127377, but perhaps I'm only moving the problem around here.

@zooba
Copy link
Member

I think this is just moving stuff around. It might end up being the right places, but let's see the Discourse discussion play out a bit first.

@barneygalebarneygale changed the titleGH-125413: pathlib ABCs: replace_scandir() with_infoGH-125413: pathlib ABCs: replace_scandir() with_statusDec 9, 2024
@barneygalebarneygale changed the titleGH-125413: pathlib ABCs: replace_scandir() with_statusGH-125413: Addpathlib.Path.status attributeDec 9, 2024
@barneygalebarneygale marked this pull request as draftDecember 9, 2024 20:58
@barneygale
Copy link
ContributorAuthor

I've revised the PR to be a more complete implementation of what I described on the forum, mostly as a demonstration/proof-of-concept at this stage.

@barneygalebarneygale added the type-featureA feature request or enhancement labelDec 9, 2024
@barneygale
Copy link
ContributorAuthor

Right, I think this is ready for review. Alyssa, sorry if this seems like deja-vu!

@barneygalebarneygale changed the titleGH-125413: Addpathlib.Path.status attributeGH-125413: Addpathlib.Path.info attributeDec 21, 2024
Copy link
Member

@encukouencukou left a comment

Choose a reason for hiding this comment

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

This looks great, thank you!
I do have a nitpick:

barneygale reacted with thumbs up emoji
@barneygale
Copy link
ContributorAuthor

Thank you Petr :) I'll wait another month until I merge, in case Alyssa or Steve have feedback

@barneygale
Copy link
ContributorAuthor

I'll merge this on Friday if there's no further feedback. Cheers

encukou reacted with thumbs up emoji

@barneygalebarneygale merged commit718ab66 intopython:mainFeb 8, 2025
39 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@encukouencukouencukou approved these changes

@zoobazoobaAwaiting requested review from zooba

@ncoghlanncoghlanAwaiting requested review from ncoghlan

Assignees
No one assigned
Labels
topic-pathlibtype-featureA feature request or enhancement
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@barneygale@zooba@encukou

[8]ページ先頭

©2009-2025 Movatter.jp