Skip to content

Commit

Permalink
pythongh-118263: Add additional arguments to path_t (Argument Clinic …
Browse files Browse the repository at this point in the history
…type) in posixmodule (pythonGH-118355)
  • Loading branch information
nineteendo committed May 27, 2024
1 parent 8d7e54a commit a7f3e06
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 267 deletions.
10 changes: 1 addition & 9 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def expandvars(path):
# Previously, this function also truncated pathnames to 8+3 format,
# but as this module is called "ntpath", that's obviously wrong!
try:
from nt import _path_normpath
from nt import _path_normpath as normpath

except ImportError:
def normpath(path):
Expand Down Expand Up @@ -560,14 +560,6 @@ def normpath(path):
comps.append(curdir)
return prefix + sep.join(comps)

else:
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
path = os.fspath(path)
if isinstance(path, bytes):
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
return _path_normpath(path) or "."


def _abspath_fallback(path):
"""Return the absolute version of a path as a fallback function in case
Expand Down
10 changes: 1 addition & 9 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def expandvars(path):
# if it contains symbolic links!

try:
from posix import _path_normpath
from posix import _path_normpath as normpath

except ImportError:
def normpath(path):
Expand Down Expand Up @@ -404,14 +404,6 @@ def normpath(path):
path = initial_slashes + sep.join(comps)
return path or dot

else:
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
path = os.fspath(path)
if isinstance(path, bytes):
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
return _path_normpath(path) or "."


def abspath(path):
"""Return an absolute path."""
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,8 @@ 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.normpath is nt._path_normpath)
self.assertFalse(inspect.isfunction(os.path.normpath))
self.assertTrue(os.path.isdir is nt._path_isdir)
self.assertFalse(inspect.isfunction(os.path.isdir))
self.assertTrue(os.path.isfile is nt._path_isfile)
Expand Down
11 changes: 10 additions & 1 deletion Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import inspect
import os
import posixpath
import sys
import unittest
from posixpath import realpath, abspath, dirname, basename
from test import test_genericpath
from test.support import import_helper
from test.support import os_helper
from test.support import cpython_only, os_helper
from test.support.os_helper import FakePath
from unittest import mock

Expand Down Expand Up @@ -273,6 +274,14 @@ def fake_lstat(path):
def test_isjunction(self):
self.assertFalse(posixpath.isjunction(ABSTFN))

@unittest.skipIf(sys.platform == 'win32', "Fast paths are not 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
self.assertTrue(os.path.normpath is posix._path_normpath)
self.assertFalse(inspect.isfunction(os.path.normpath))

def test_expanduser(self):
self.assertEqual(posixpath.expanduser("foo"), "foo")
self.assertEqual(posixpath.expanduser(b"foo"), b"foo")
Expand Down
Loading

0 comments on commit a7f3e06

Please sign in to comment.