-
-
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
Changes from 10 commits
9a7d3d8
a07f1e7
7765fea
684d683
781fa07
dda7be7
565c2e1
53b932b
f6ce580
88c8b25
39beb86
9d4af5a
1030d8a
be6b592
0e465dc
8fff56b
dcb9513
0d2985d
19018dc
7583a1d
30cf754
c0991ec
3400f07
cb7cea3
636886e
05c9165
5818815
ff6bca9
6d48808
c7128bc
a72aba0
aac93e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||||||||||||||||||||||||||||
|
@@ -889,6 +890,26 @@ 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): | ||||||||||||||||||||||||||||||
current_drive = os.path.splitdrive(os.path.abspath(__file__))[0] + "\\" | ||||||||||||||||||||||||||||||
self.assertFalse(os.path.isfile(current_drive)) | ||||||||||||||||||||||||||||||
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. The reason this is false is because a relative drive path like "C:" resolves to the working directory on the drive. Did you want to test a volume device path like 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. Ah, yes. And this is exactly the thing that (erroneously) returns |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@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 | ||||||||||||||||||||||||||||||
|
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 | ||
mdboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
API calls. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.