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 — Support for not following symlinks in pathlib.Path.is_dir() · Issue #105793 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Support for not following symlinks in pathlib.Path.is_dir()#105793
Copy link
Labels
3.13only security fixesonly security fixestopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement

Description

@barneygale
barneygale
opened on Jun 14, 2023
Issue body actions

Feature or enhancement

Add a follow_symlinks argument to pathlib.Path.is_dir(), defaulting to True

Pitch

Pathlib's walk() and glob() implementations are built upon os.scandir(), which yields os.DirEntry objects. The interface for os.DirEntry is a rough subset of pathlib.Path, including the name attribute and is_dir() method.

Pathlib only ever calls os.scandir() via a private pathlib.Path._scandir() method, currently defined as follows:

    def _scandir(self):
        return os.scandir(self)

In future I'd like to add a pathlib.AbstractPath class with abstract stat(), iterdir() and open() methods.

The default implementation of AbstractPath._scandir() would use iterdir():

   def _scandir(self):
       return contextlib.nullcontext(list(self.iterdir()))

Note how it returns AbstractPath objects, and not DirEntry objects. This exploits the similarities of the Path and DirEntry APIs.

... but there's a problem!

The os.DirEntry.is_dir() method accepts a keyword-only follow_symlinks argument. Our globbing implementation requires us to set this argument. But the Path.is_dir() method does not accept this argument!

If we add a keyword-only follow_symlinks argument to Path.is_dir(), we make it compatible with os.DirEntry.is_dir(), which in turn allows us to build a glob() implementation upon user-defined stat() and iterdir() methods in a future AbstractPath class.

Previous discussion

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

We added a follow_symlinks argument to Path.exists() in #89769 / #29655.

Linked PRs

  • GH-105793: Add follow_symlinks argument to pathlib.Path.is_dir() and is_file() #105794

Activity

  1. barneygale
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-pathlib
    3.13only security fixesonly security fixes
    on Jun 14, 2023
  2. barneygale
    added a commit that references this issue on Jun 14, 2023

    pythonGH-105793: Add follow_symlinks argument to pathlib.Path.is_dir()

    7c2c51a
  3. eryksun commented on Jun 14, 2023

    @eryksun
    eryksun
    on Jun 14, 2023
    Contributor
    More actions

    Path.is_file() may as well also support follow_symlinks, as is implemented for DirEntry.is_file().

    Reacted by Barney Gale
  4. barneygale
    added 4 commits that reference this issue on Jun 15, 2023

    Merge branch 'main' into pythongh-105793-is-dir-follow-symlinks

    1323b7a

    Merge branch 'main' into pythongh-105793-is-dir-follow-symlinks

    a1a7039

    Merge branch 'main' into pythongh-105793-is-dir-follow-symlinks

    b248777

    GH-105793: Add follow_symlinks argument to `pathlib.Path.is_dir()` an…

    219effa
  5. barneygale commented on Jun 26, 2023

    @barneygale
    barneygale
    on Jun 26, 2023
    ContributorAuthor
    More actions

    Implemented in:

    • 3.13 / 219effa / GH-105793: Add follow_symlinks argument to pathlib.Path.is_dir() and is_file() #105794

    Thank you Steve for the review and Eryk for the is_file() suggestion :-)

  6. barneygale
    closed this as completedon Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixestopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.