-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-101196: Make isdir/isfile/exists faster on Windows #101324
Merged
Merged
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9a7d3d8
Make isdir/isfile/exists faster on Windows
mdboom a07f1e7
Fix doc syntax
mdboom 7765fea
Merge branch 'main' into win-isdir-fastpath
mdboom 684d683
Fix doc syntax
mdboom 781fa07
Update Lib/ntpath.py
mdboom dda7be7
Mark test as CPython-only
mdboom 565c2e1
Handle files correctly
mdboom 53b932b
Remove unused variable
mdboom f6ce580
Add islink
mdboom 88c8b25
Update CHANGELOG entry
mdboom 39beb86
Handle uncommon error cases
mdboom 9d4af5a
Fix drive test
mdboom 1030d8a
Update Lib/test/test_ntpath.py
mdboom be6b592
Use STAT and LSTAT macros
mdboom 0e465dc
Fix and add more tests
mdboom 8fff56b
Merge remote-tracking branch 'origin/win-isdir-fastpath' into win-isd…
mdboom dcb9513
Don't unnecessarily zero-out info
mdboom 0d2985d
Fix spelling of Win32
mdboom 19018dc
PEP7
mdboom 7583a1d
Reduce use of else
mdboom 30cf754
Remove variable declarations
mdboom c0991ec
Docstring improvements
mdboom 3400f07
No need for 'error' local variable
mdboom cb7cea3
Update generated code
mdboom 636886e
PEP7
mdboom 05c9165
Make docs consistent
mdboom 5818815
Merge branch 'main' into win-isdir-fastpath
mdboom ff6bca9
Revert docstrings to the equivalent Python ones
mdboom 6d48808
Revert docs changes
mdboom c7128bc
Move islink to genericpath.py
mdboom a72aba0
Regenerate clinic
mdboom aac93e4
Rename and reorganize - _isdir -> _path_isdir etc.
mdboom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,9 +1,10 @@ | ||||||||||||||||||||||||||||||
import inspect | ||||||||||||||||||||||||||||||
import ntpath | ||||||||||||||||||||||||||||||
import os | ||||||||||||||||||||||||||||||
import sys | ||||||||||||||||||||||||||||||
import unittest | ||||||||||||||||||||||||||||||
import warnings | ||||||||||||||||||||||||||||||
from test.support import os_helper | ||||||||||||||||||||||||||||||
from test.support import cpython_only, os_helper | ||||||||||||||||||||||||||||||
from test.support import TestFailed, is_emscripten | ||||||||||||||||||||||||||||||
from test.support.os_helper import FakePath | ||||||||||||||||||||||||||||||
from test import test_genericpath | ||||||||||||||||||||||||||||||
|
@@ -938,6 +939,35 @@ def test_isjunction(self): | |||||||||||||||||||||||||||||
self.assertFalse(ntpath.isjunction('tmpdir')) | ||||||||||||||||||||||||||||||
self.assertPathEqual(ntpath.realpath('testjunc'), ntpath.realpath('tmpdir')) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@unittest.skipIf(sys.platform != 'win32', "drive letters are a windows concept") | ||||||||||||||||||||||||||||||
def test_isfile_driveletter(self): | ||||||||||||||||||||||||||||||
drive = os.environ.get('SystemDrive') | ||||||||||||||||||||||||||||||
if drive is None or len(drive) != 2 or drive[1] != ':': | ||||||||||||||||||||||||||||||
raise unittest.SkipTest('SystemDrive is not defined or malformed') | ||||||||||||||||||||||||||||||
self.assertFalse(os.path.isfile('\\\\.\\' + drive)) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@unittest.skipIf(sys.platform != 'win32', "windows only") | ||||||||||||||||||||||||||||||
def test_con_device(self): | ||||||||||||||||||||||||||||||
self.assertFalse(os.path.isfile(r"\\.\CON")) | ||||||||||||||||||||||||||||||
self.assertFalse(os.path.isdir(r"\\.\CON")) | ||||||||||||||||||||||||||||||
self.assertFalse(os.path.islink(r"\\.\CON")) | ||||||||||||||||||||||||||||||
self.assertTrue(os.path.exists(r"\\.\CON")) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@unittest.skipIf(sys.platform != 'win32', "Fast paths are only for win32") | ||||||||||||||||||||||||||||||
@cpython_only | ||||||||||||||||||||||||||||||
def test_fast_paths_in_use(self): | ||||||||||||||||||||||||||||||
# There are fast paths of these functions implemented in posixmodule.c. | ||||||||||||||||||||||||||||||
# Confirm that they are being used, and not the Python fallbacks in | ||||||||||||||||||||||||||||||
# genericpath.py. | ||||||||||||||||||||||||||||||
self.assertTrue(os.path.isdir is nt._isdir) | ||||||||||||||||||||||||||||||
self.assertFalse(inspect.isfunction(os.path.isdir)) | ||||||||||||||||||||||||||||||
self.assertTrue(os.path.isfile is nt._isfile) | ||||||||||||||||||||||||||||||
self.assertFalse(inspect.isfunction(os.path.isfile)) | ||||||||||||||||||||||||||||||
self.assertTrue(os.path.islink is nt._islink) | ||||||||||||||||||||||||||||||
self.assertFalse(inspect.isfunction(os.path.islink)) | ||||||||||||||||||||||||||||||
self.assertTrue(os.path.exists is nt._exists) | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
self.assertFalse(inspect.isfunction(os.path.exists)) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase): | ||||||||||||||||||||||||||||||
pathmodule = ntpath | ||||||||||||||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Windows/2023-01-25-11-33-54.gh-issue-101196.wAX_2g.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The functions ``os.path.isdir``, ``os.path.isfile``, ``os.path.islink`` and | ||
``os.path.exists`` are now 13% to 28% faster on Windows, by making fewer Win32 | ||
API calls. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.