gh-136437: Make several functions in `os.path` pos-only (#136949) · python/cpython@99cdf1d

GitHub

@@ -47,7 +47,7 @@ def _get_bothseps(path):

4747LOCALE_NAME_INVARIANTas_LOCALE_NAME_INVARIANT,

4848LCMAP_LOWERCASEas_LCMAP_LOWERCASE)

494950-defnormcase(s):

50+defnormcase(s, /):

5151"""Normalize case of pathname.

52525353 Makes all characters lowercase and all slashes into backslashes.

@@ -66,7 +66,7 @@ def normcase(s):

6666_LCMAP_LOWERCASE,

6767s.replace('/', '\\'))

6868exceptImportError:

69-defnormcase(s):

69+defnormcase(s, /):

7070"""Normalize case of pathname.

71717272 Makes all characters lowercase and all slashes into backslashes.

@@ -77,7 +77,7 @@ def normcase(s):

7777returns.replace('/', '\\').lower()

7878797980-defisabs(s):

80+defisabs(s, /):

8181"""Test whether a path is absolute"""

8282s=os.fspath(s)

8383ifisinstance(s, bytes):

@@ -96,7 +96,7 @@ def isabs(s):

969697979898# Join two (or more) paths.

99-defjoin(path, *paths):

99+defjoin(path, /, *paths):

100100path=os.fspath(path)

101101ifisinstance(path, bytes):

102102sep=b'\\'

@@ -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-defsplitdrive(p):

146+defsplitdrive(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):

169169try:

170170fromntimport_path_splitroot_exassplitroot

171171exceptImportError:

172-defsplitroot(p):

172+defsplitroot(p, /):

173173"""Split a pathname into drive, root and tail.

174174175175 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.

221221222-defsplit(p):

222+defsplit(p, /):

223223"""Split a pathname.

224224225225 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.

242242243-defsplitext(p):

243+defsplitext(p, /):

244244p=os.fspath(p)

245245ifisinstance(p, bytes):

246246returngenericpath._splitext(p, b'\\', b'/', b'.')

@@ -251,14 +251,14 @@ def splitext(p):

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

253253254-defbasename(p):

254+defbasename(p, /):

255255"""Returns the final component of a pathname"""

256256returnsplit(p)[1]

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

260260261-defdirname(p):

261+defdirname(p, /):

262262"""Returns the directory component of a pathname"""

263263returnsplit(p)[0]

264264@@ -601,7 +601,7 @@ def abspath(path):

601601fromntimport_findfirstfile, _getfinalpathname, readlinkas_nt_readlink

602602exceptImportError:

603603# realpath is a no-op on systems without _getfinalpathname support.

604-defrealpath(path, *, strict=False):

604+defrealpath(path, /, *, strict=False):

605605returnabspath(path)

606606else:

607607def_readlink_deep(path, ignored_error=OSError):

@@ -702,7 +702,7 @@ def _getfinalpathname_nonstrict(path, ignored_error=OSError):

702702tail=join(name, tail) iftailelsename

703703returntail

704704705-defrealpath(path, *, strict=False):

705+defrealpath(path, /, *, strict=False):

706706path=normpath(path)

707707ifisinstance(path, bytes):

708708prefix=b'\\\\?\\'