mirror of
https://github.com/python/cpython.git
synced 2025-10-25 18:54:53 +00:00
gh-136437: Make several functions in os.path pos-only (#136949)
This commit is contained in:
parent
e41c1ce585
commit
99cdf1deb6
5 changed files with 51 additions and 147 deletions
|
|
@ -47,7 +47,7 @@ def _get_bothseps(path):
|
|||
LOCALE_NAME_INVARIANT as _LOCALE_NAME_INVARIANT,
|
||||
LCMAP_LOWERCASE as _LCMAP_LOWERCASE)
|
||||
|
||||
def normcase(s):
|
||||
def normcase(s, /):
|
||||
"""Normalize case of pathname.
|
||||
|
||||
Makes all characters lowercase and all slashes into backslashes.
|
||||
|
|
@ -66,7 +66,7 @@ def normcase(s):
|
|||
_LCMAP_LOWERCASE,
|
||||
s.replace('/', '\\'))
|
||||
except ImportError:
|
||||
def normcase(s):
|
||||
def normcase(s, /):
|
||||
"""Normalize case of pathname.
|
||||
|
||||
Makes all characters lowercase and all slashes into backslashes.
|
||||
|
|
@ -77,7 +77,7 @@ def normcase(s):
|
|||
return s.replace('/', '\\').lower()
|
||||
|
||||
|
||||
def isabs(s):
|
||||
def isabs(s, /):
|
||||
"""Test whether a path is absolute"""
|
||||
s = os.fspath(s)
|
||||
if isinstance(s, bytes):
|
||||
|
|
@ -96,7 +96,7 @@ def isabs(s):
|
|||
|
||||
|
||||
# Join two (or more) paths.
|
||||
def join(path, *paths):
|
||||
def join(path, /, *paths):
|
||||
path = os.fspath(path)
|
||||
if isinstance(path, bytes):
|
||||
sep = b'\\'
|
||||
|
|
@ -143,7 +143,7 @@ def join(path, *paths):
|
|||
# Split a path in a drive specification (a drive letter followed by a
|
||||
# colon) and the path specification.
|
||||
# It is always true that drivespec + pathspec == p
|
||||
def splitdrive(p):
|
||||
def splitdrive(p, /):
|
||||
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
|
||||
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ def splitdrive(p):
|
|||
try:
|
||||
from nt import _path_splitroot_ex as splitroot
|
||||
except ImportError:
|
||||
def splitroot(p):
|
||||
def splitroot(p, /):
|
||||
"""Split a pathname into drive, root and tail.
|
||||
|
||||
The tail contains anything after the root."""
|
||||
|
|
@ -219,7 +219,7 @@ def splitroot(p):
|
|||
# join(head, tail) == p holds.
|
||||
# The resulting head won't end in '/' unless it is the root.
|
||||
|
||||
def split(p):
|
||||
def split(p, /):
|
||||
"""Split a pathname.
|
||||
|
||||
Return tuple (head, tail) where tail is everything after the final slash.
|
||||
|
|
@ -240,7 +240,7 @@ def split(p):
|
|||
# pathname component; the root is everything before that.
|
||||
# It is always true that root + ext == p.
|
||||
|
||||
def splitext(p):
|
||||
def splitext(p, /):
|
||||
p = os.fspath(p)
|
||||
if isinstance(p, bytes):
|
||||
return genericpath._splitext(p, b'\\', b'/', b'.')
|
||||
|
|
@ -251,14 +251,14 @@ def splitext(p):
|
|||
|
||||
# Return the tail (basename) part of a path.
|
||||
|
||||
def basename(p):
|
||||
def basename(p, /):
|
||||
"""Returns the final component of a pathname"""
|
||||
return split(p)[1]
|
||||
|
||||
|
||||
# Return the head (dirname) part of a path.
|
||||
|
||||
def dirname(p):
|
||||
def dirname(p, /):
|
||||
"""Returns the directory component of a pathname"""
|
||||
return split(p)[0]
|
||||
|
||||
|
|
@ -601,7 +601,7 @@ def abspath(path):
|
|||
from nt import _findfirstfile, _getfinalpathname, readlink as _nt_readlink
|
||||
except ImportError:
|
||||
# realpath is a no-op on systems without _getfinalpathname support.
|
||||
def realpath(path, *, strict=False):
|
||||
def realpath(path, /, *, strict=False):
|
||||
return abspath(path)
|
||||
else:
|
||||
def _readlink_deep(path, ignored_error=OSError):
|
||||
|
|
@ -702,7 +702,7 @@ def _getfinalpathname_nonstrict(path, ignored_error=OSError):
|
|||
tail = join(name, tail) if tail else name
|
||||
return tail
|
||||
|
||||
def realpath(path, *, strict=False):
|
||||
def realpath(path, /, *, strict=False):
|
||||
path = normpath(path)
|
||||
if isinstance(path, bytes):
|
||||
prefix = b'\\\\?\\'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue