Skip to content

Commit 4285212

Browse files
committed
gh-136437: Make several functions in os.path pos-only
1 parent 3224429 commit 4285212

File tree

4 files changed

+32
-96
lines changed

4 files changed

+32
-96
lines changed

Lib/ntpath.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _get_bothseps(path):
4747
LOCALE_NAME_INVARIANT as _LOCALE_NAME_INVARIANT,
4848
LCMAP_LOWERCASE as _LCMAP_LOWERCASE)
4949

50-
def normcase(s):
50+
def normcase(s, /):
5151
"""Normalize case of pathname.
5252
5353
Makes all characters lowercase and all slashes into backslashes.
@@ -66,7 +66,7 @@ def normcase(s):
6666
_LCMAP_LOWERCASE,
6767
s.replace('/', '\\'))
6868
except ImportError:
69-
def normcase(s):
69+
def normcase(s, /):
7070
"""Normalize case of pathname.
7171
7272
Makes all characters lowercase and all slashes into backslashes.
@@ -77,7 +77,7 @@ def normcase(s):
7777
return s.replace('/', '\\').lower()
7878

7979

80-
def isabs(s):
80+
def isabs(s, /):
8181
"""Test whether a path is absolute"""
8282
s = os.fspath(s)
8383
if isinstance(s, bytes):
@@ -143,7 +143,7 @@ def join(path, *paths):
143143
# Split a path in a drive specification (a drive letter followed by a
144144
# colon) and the path specification.
145145
# It is always true that drivespec + pathspec == p
146-
def splitdrive(p):
146+
def splitdrive(p, /):
147147
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
148148
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
149149
@@ -169,7 +169,7 @@ def splitdrive(p):
169169
try:
170170
from nt import _path_splitroot_ex as splitroot
171171
except ImportError:
172-
def splitroot(p):
172+
def splitroot(p, /):
173173
"""Split a pathname into drive, root and tail.
174174
175175
The tail contains anything after the root."""
@@ -219,7 +219,7 @@ def splitroot(p):
219219
# join(head, tail) == p holds.
220220
# The resulting head won't end in '/' unless it is the root.
221221

222-
def split(p):
222+
def split(p, /):
223223
"""Split a pathname.
224224
225225
Return tuple (head, tail) where tail is everything after the final slash.
@@ -240,7 +240,7 @@ def split(p):
240240
# pathname component; the root is everything before that.
241241
# It is always true that root + ext == p.
242242

243-
def splitext(p):
243+
def splitext(p, /):
244244
p = os.fspath(p)
245245
if isinstance(p, bytes):
246246
return genericpath._splitext(p, b'\\', b'/', b'.')
@@ -251,14 +251,14 @@ def splitext(p):
251251

252252
# Return the tail (basename) part of a path.
253253

254-
def basename(p):
254+
def basename(p, /):
255255
"""Returns the final component of a pathname"""
256256
return split(p)[1]
257257

258258

259259
# Return the head (dirname) part of a path.
260260

261-
def dirname(p):
261+
def dirname(p, /):
262262
"""Returns the directory component of a pathname"""
263263
return split(p)[0]
264264

Lib/posixpath.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ def _get_sep(path):
5050
# normalizations (such as optimizing '../' away) are not allowed
5151
# (another function should be defined to do that).
5252

53-
def normcase(s):
53+
def normcase(s, /):
5454
"""Normalize case of pathname. Has no effect under Posix"""
5555
return os.fspath(s)
5656

5757

5858
# Return whether a path is absolute.
5959
# Trivial in Posix, harder on the Mac or MS-DOS.
6060

61-
def isabs(s):
61+
def isabs(s, /):
6262
"""Test whether a path is absolute"""
6363
s = os.fspath(s)
6464
sep = _get_sep(s)
@@ -97,7 +97,7 @@ def join(a, *p):
9797
# '/' in the path, head will be empty.
9898
# Trailing '/'es are stripped from head unless it is the root.
9999

100-
def split(p):
100+
def split(p, /):
101101
"""Split a pathname. Returns tuple "(head, tail)" where "tail" is
102102
everything after the final slash. Either part may be empty."""
103103
p = os.fspath(p)
@@ -114,7 +114,7 @@ def split(p):
114114
# pathname component; the root is everything before that.
115115
# It is always true that root + ext == p.
116116

117-
def splitext(p):
117+
def splitext(p, /):
118118
p = os.fspath(p)
119119
if isinstance(p, bytes):
120120
sep = b'/'
@@ -128,7 +128,7 @@ def splitext(p):
128128
# Split a pathname into a drive specification and the rest of the
129129
# path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
130130

131-
def splitdrive(p):
131+
def splitdrive(p, /):
132132
"""Split a pathname into drive and path. On Posix, drive is always
133133
empty."""
134134
p = os.fspath(p)
@@ -138,7 +138,7 @@ def splitdrive(p):
138138
try:
139139
from posix import _path_splitroot_ex as splitroot
140140
except ImportError:
141-
def splitroot(p):
141+
def splitroot(p, /):
142142
"""Split a pathname into drive, root and tail.
143143
144144
The tail contains anything after the root."""
@@ -163,7 +163,7 @@ def splitroot(p):
163163

164164
# Return the tail (basename) part of a path, same as split(path)[1].
165165

166-
def basename(p):
166+
def basename(p, /):
167167
"""Returns the final component of a pathname"""
168168
p = os.fspath(p)
169169
sep = _get_sep(p)
@@ -173,7 +173,7 @@ def basename(p):
173173

174174
# Return the head (dirname) part of a path, same as split(path)[0].
175175

176-
def dirname(p):
176+
def dirname(p, /):
177177
"""Returns the directory component of a pathname"""
178178
p = os.fspath(p)
179179
sep = _get_sep(p)

Modules/clinic/posixmodule.c.h

Lines changed: 9 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5535,15 +5535,16 @@ os__path_lexists_impl(PyObject *module, path_t *path)
55355535
/*[clinic input]
55365536
os._path_isdir -> bool
55375537
5538-
s as path: path_t(allow_fd=True, suppress_value_error=True)
5538+
s as path: path_t(allow_fd=True, suppress_value_error=True),
5539+
/
55395540
55405541
Return true if the pathname refers to an existing directory.
55415542
55425543
[clinic start generated code]*/
55435544

55445545
static int
55455546
os__path_isdir_impl(PyObject *module, path_t *path)
5546-
/*[clinic end generated code: output=d5786196f9e2fa7a input=132a3b5301aecf79]*/
5547+
/*[clinic end generated code: output=d5786196f9e2fa7a input=6d3c18234e720b19]*/
55475548
{
55485549
return _testFileType(path, PY_IFDIR);
55495550
}
@@ -5612,7 +5613,8 @@ os__path_isjunction_impl(PyObject *module, path_t *path)
56125613
/*[clinic input]
56135614
os._path_splitroot_ex
56145615
5615-
p as path: path_t(make_wide=True, nonstrict=True)
5616+
p as path: path_t(make_wide=True, nonstrict=True),
5617+
/
56165618
56175619
Split a pathname into drive, root and tail.
56185620
@@ -5621,7 +5623,7 @@ The tail contains anything after the root.
56215623

56225624
static PyObject *
56235625
os__path_splitroot_ex_impl(PyObject *module, path_t *path)
5624-
/*[clinic end generated code: output=4b0072b6cdf4b611 input=4556b615c7cc13f2]*/
5626+
/*[clinic end generated code: output=4b0072b6cdf4b611 input=ccd3dfece9b2d79a]*/
56255627
{
56265628
Py_ssize_t drvsize, rootsize;
56275629
PyObject *drv = NULL, *root = NULL, *tail = NULL, *result = NULL;

0 commit comments

Comments
 (0)