File tree 7 files changed +314
-267
lines changed
Filter options
Misc/NEWS.d/next/Core and Builtins
7 files changed +314
-267
lines changed
Original file line number Diff line number Diff line change @@ -521,7 +521,7 @@ def expandvars(path):
521
521
# Previously, this function also truncated pathnames to 8+3 format,
522
522
# but as this module is called "ntpath", that's obviously wrong!
523
523
try :
524
- from nt import _path_normpath
524
+ from nt import _path_normpath as normpath
525
525
526
526
except ImportError :
527
527
def normpath (path ):
@@ -560,14 +560,6 @@ def normpath(path):
560
560
comps .append (curdir )
561
561
return prefix + sep .join (comps )
562
562
563
- else :
564
- def normpath (path ):
565
- """Normalize path, eliminating double slashes, etc."""
566
- path = os .fspath (path )
567
- if isinstance (path , bytes ):
568
- return os .fsencode (_path_normpath (os .fsdecode (path ))) or b"."
569
- return _path_normpath (path ) or "."
570
-
571
563
572
564
def _abspath_fallback (path ):
573
565
"""Return the absolute version of a path as a fallback function in case
Original file line number Diff line number Diff line change @@ -371,7 +371,7 @@ def expandvars(path):
371
371
# if it contains symbolic links!
372
372
373
373
try :
374
- from posix import _path_normpath
374
+ from posix import _path_normpath as normpath
375
375
376
376
except ImportError :
377
377
def normpath (path ):
@@ -404,14 +404,6 @@ def normpath(path):
404
404
path = initial_slashes + sep .join (comps )
405
405
return path or dot
406
406
407
- else :
408
- def normpath (path ):
409
- """Normalize path, eliminating double slashes, etc."""
410
- path = os .fspath (path )
411
- if isinstance (path , bytes ):
412
- return os .fsencode (_path_normpath (os .fsdecode (path ))) or b"."
413
- return _path_normpath (path ) or "."
414
-
415
407
416
408
def abspath (path ):
417
409
"""Return an absolute path."""
Original file line number Diff line number Diff line change @@ -1010,6 +1010,8 @@ def test_fast_paths_in_use(self):
1010
1010
# There are fast paths of these functions implemented in posixmodule.c.
1011
1011
# Confirm that they are being used, and not the Python fallbacks in
1012
1012
# genericpath.py.
1013
+ self .assertTrue (os .path .normpath is nt ._path_normpath )
1014
+ self .assertFalse (inspect .isfunction (os .path .normpath ))
1013
1015
self .assertTrue (os .path .isdir is nt ._path_isdir )
1014
1016
self .assertFalse (inspect .isfunction (os .path .isdir ))
1015
1017
self .assertTrue (os .path .isfile is nt ._path_isfile )
Original file line number Diff line number Diff line change
1
+ import inspect
1
2
import os
2
3
import posixpath
3
4
import sys
4
5
import unittest
5
6
from posixpath import realpath , abspath , dirname , basename
6
7
from test import test_genericpath
7
8
from test .support import import_helper
8
- from test .support import os_helper
9
+ from test .support import cpython_only , os_helper
9
10
from test .support .os_helper import FakePath
10
11
from unittest import mock
11
12
@@ -273,6 +274,14 @@ def fake_lstat(path):
273
274
def test_isjunction (self ):
274
275
self .assertFalse (posixpath .isjunction (ABSTFN ))
275
276
277
+ @unittest .skipIf (sys .platform == 'win32' , "Fast paths are not for win32" )
278
+ @cpython_only
279
+ def test_fast_paths_in_use (self ):
280
+ # There are fast paths of these functions implemented in posixmodule.c.
281
+ # Confirm that they are being used, and not the Python fallbacks
282
+ self .assertTrue (os .path .normpath is posix ._path_normpath )
283
+ self .assertFalse (inspect .isfunction (os .path .normpath ))
284
+
276
285
def test_expanduser (self ):
277
286
self .assertEqual (posixpath .expanduser ("foo" ), "foo" )
278
287
self .assertEqual (posixpath .expanduser (b"foo" ), b"foo" )
Original file line number Diff line number Diff line change
1
+ Speed up :func: `os.path.normpath ` with a direct C call.
You can’t perform that action at this time.
0 commit comments