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 — Refactor `nt._path_is*` & `nt._path_[l]exists` · Issue #118507 · python/cpython

Refactor nt._path_is* & nt._path_[l]exists #118507

New issue
Copy link
New issue
Copy link
Closed
Closed
Refactor nt._path_is* & nt._path_[l]exists#118507
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@nineteendo
nineteendo
opened on May 2, 2024
Issue body actions

Feature or enhancement

Proposal:

Quoting @eryksun:

I agree that all of these _path_is* and _path_[l]exists helpers are a lot of code to maintain, taken together. It could be refactored into smaller inline helper functions that can be reused, which would also make the code more readable.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

  • gh-117841: Add C implementation of ntpath.lexists #117842

Linked PRs

  • gh-118507 : Refactor nt._path_is* #118755
  • [3.13] gh-118507 : Refactor nt._path_is* to improve applicability for other cases (GH-118755) #119360
  • [3.12] gh-118507 : Fix ntpath.isfile for pipes. #119381
  • [3.12] gh-118507 : Speed up ntpath.isjunction() & ntpath.lexists() with native helpers (GH-118755) #119420
  • gh-118507: Amend news entry #120817
  • [3.13] gh-118507: Amend news entry to mention ntpath.isfile bugfix (GH-120817) #121365

Activity

  1. nineteendo
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on May 2, 2024
  2. nineteendo commented on May 6, 2024

    @nineteendo
    nineteendo
    on May 6, 2024
    ContributorAuthor
    More actions

    Eryk, do you have any ideas to clean them up (besides the simpler error handling)?

  3. eryksun commented on May 7, 2024

    @eryksun
    eryksun
    on May 7, 2024 · Hidden as resolved
    show commentMore actions
  4. nineteendo commented on May 7, 2024

    @nineteendo
    nineteendo
    on May 7, 2024
    ContributorAuthor
    More actions

    Good start, we probably need a follow_symlinks option for _testFileTypeByName to use LSTAT() though.

  5. eryksun commented on May 7, 2024

    @eryksun
    eryksun
    on May 7, 2024 · Hidden as resolved
    show commentMore actions
  6. eryksun commented on May 7, 2024

    @eryksun
    eryksun
    on May 7, 2024 · Hidden as resolved
    show commentMore actions
  7. nineteendo commented on May 8, 2024

    @nineteendo
    nineteendo
    on May 8, 2024
    ContributorAuthor
    More actions

    Did you speed something up, because it's only 3 lines less than the old code.

  8. eryksun commented on May 8, 2024

    @eryksun
    eryksun
    on May 8, 2024
    Contributor
    More actions

    My goal was to remove duplicated code and divide the work into two separate operations that can be understood and modified independently, written in a way that I think is easy to understand. This reduces the maintenance burden. I also added internal support for checking for mount points, in case we implement _path_isjunction().

    I added a GetFileType() check in the by-handle code. When combined with the diskOnly parameter, the GetFileType() check makes it safer to check an open file descriptor since the check is implemented directly in the I/O manager without trying to acquire the file lock. If GetFileInformationByHandleEx() is called on a handle for a synchronous-mode pipe, it could block indefinitely. For example, with the current implementation in 3.12:

    >>> pr, pw = os.pipe()
    >>> threading.Thread(target=os.read, args=(pr, 1)).start()
    >>> os.path.isfile(pr)
    ^C

    Also, given the system's named-pipe filesystem (NPFS) support for basic file information (anonymous pipes are also in NPFS, but they're like unlinked open files in POSIX), the GetFileType() check avoids classifying pipes as regular files. Again, with the current implementation in 3.12:

    >>> pr, pw = os.pipe()
    >>> os.path.isfile(pr)
    True
    Reacted by Nice Zombies
  9. nineteendo commented on May 8, 2024

    @nineteendo
    nineteendo
    on May 8, 2024
    ContributorAuthor
    More actions

    OK, that explains why the code isn't much shorter. I added a test for the second issue. The first one seems difficult to test.

  10. zooba
    added a commit that references this issue on May 21, 2024

    gh-118507 : Refactor `nt._path_is*` to improve applicability for othe…

    b641825
  11. miss-islington
    added a commit that references this issue on May 21, 2024

    pythongh-118507 : Refactor `nt._path_is*` to improve applicability fo…

    4f46562
  12. zooba
    added a commit that references this issue on May 22, 2024

    gh-118507 : Refactor `nt._path_is*` to improve applicability for othe…

    f15fbe9
  13. nineteendo
    added a commit that references this issue on May 22, 2024

    pythongh-118507 : Refactor `nt._path_is*` to improve applicability fo…

    2fb9812
  14. zooba
    added a commit that references this issue on May 22, 2024

    gh-118507 : Refactor ntpath native functions (gh-119381)

    874a4f7
  15. erlend-aasland
    closed this as completedon May 30, 2024
  16. zooba
    added 3 commits that reference this issue on Jul 4, 2024

    gh-118507: Amend news entry to mention ntpath.isfile bugfix (GH-120817)

    db17291

    pythongh-118507: Amend news entry to mention ntpath.isfile bugfix

    06028a4

    gh-118507: Amend news entry to mention ntpath.isfile bugfix (GH-120817)

    868e9ab
  17. estyxx
    added 2 commits that reference this issue on Jul 17, 2024

    pythongh-118507 : Refactor `nt._path_is*` to improve applicability fo…

    03a3b57

    pythongh-118507: Amend news entry to mention ntpath.isfile bugfix (py…

    1aa1017
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

    type-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.