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

Support for not following symlinks in pathlib.Path.is_dir() #105793

Closed
Labels
@barneygale

Description

@barneygale

Feature or enhancement

Add afollow_symlinks argument topathlib.Path.is_dir(), defaulting toTrue

Pitch

Pathlib'swalk() andglob() implementations are built uponos.scandir(), which yieldsos.DirEntry objects. The interface foros.DirEntry is a rough subset ofpathlib.Path, including thename attribute andis_dir() method.

Pathlib only ever callsos.scandir() via a privatepathlib.Path._scandir() method, currently defined as follows:

def_scandir(self):returnos.scandir(self)

In future I'd like to add apathlib.AbstractPath class with abstractstat(),iterdir() andopen() methods.

The default implementation ofAbstractPath._scandir() would useiterdir():

def_scandir(self):returncontextlib.nullcontext(list(self.iterdir()))

Note how it returnsAbstractPath objects, and notDirEntry objects. This exploits the similarities of thePath andDirEntry APIs.

... but there's a problem!

Theos.DirEntry.is_dir() method accepts a keyword-onlyfollow_symlinks argument. Our globbing implementation requires us to set this argument. But thePath.is_dir() method does not accept this argument!

If we add a keyword-onlyfollow_symlinks argument toPath.is_dir(), we make it compatible withos.DirEntry.is_dir(), which in turn allows us to build aglob() implementation upon user-definedstat() anditerdir() methods in a futureAbstractPath class.

Previous discussion

General discussion ofAbstractPath:https://discuss.python.org/t/make-pathlib-extensible/3428

We added afollow_symlinks argument toPath.exists() in#89769 /#29655.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp