gh-136437: Make several functions in os.path pos-only (#136949)

This commit is contained in:
sobolevn 2025-07-23 14:56:02 +03:00 committed by GitHub
parent e41c1ce585
commit 99cdf1deb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 51 additions and 147 deletions

View file

@ -50,7 +50,7 @@ def _get_sep(path):
# normalizations (such as optimizing '../' away) are not allowed
# (another function should be defined to do that).
def normcase(s):
def normcase(s, /):
"""Normalize case of pathname. Has no effect under Posix"""
return os.fspath(s)
@ -58,7 +58,7 @@ def normcase(s):
# Return whether a path is absolute.
# Trivial in Posix, harder on the Mac or MS-DOS.
def isabs(s):
def isabs(s, /):
"""Test whether a path is absolute"""
s = os.fspath(s)
sep = _get_sep(s)
@ -69,7 +69,7 @@ def isabs(s):
# Ignore the previous parts if a part is absolute.
# Insert a '/' unless the first part is empty or already ends in '/'.
def join(a, *p):
def join(a, /, *p):
"""Join two or more pathname components, inserting '/' as needed.
If any component is an absolute path, all previous path components
will be discarded. An empty last part will result in a path that
@ -97,7 +97,7 @@ def join(a, *p):
# '/' in the path, head will be empty.
# Trailing '/'es are stripped from head unless it is the root.
def split(p):
def split(p, /):
"""Split a pathname. Returns tuple "(head, tail)" where "tail" is
everything after the final slash. Either part may be empty."""
p = os.fspath(p)
@ -114,7 +114,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):
sep = b'/'
@ -128,7 +128,7 @@ def splitext(p):
# Split a pathname into a drive specification and the rest of the
# path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
def splitdrive(p):
def splitdrive(p, /):
"""Split a pathname into drive and path. On Posix, drive is always
empty."""
p = os.fspath(p)
@ -138,7 +138,7 @@ def splitdrive(p):
try:
from posix 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."""
@ -163,7 +163,7 @@ def splitroot(p):
# Return the tail (basename) part of a path, same as split(path)[1].
def basename(p):
def basename(p, /):
"""Returns the final component of a pathname"""
p = os.fspath(p)
sep = _get_sep(p)
@ -173,7 +173,7 @@ def basename(p):
# Return the head (dirname) part of a path, same as split(path)[0].
def dirname(p):
def dirname(p, /):
"""Returns the directory component of a pathname"""
p = os.fspath(p)
sep = _get_sep(p)
@ -388,7 +388,7 @@ def abspath(path):
# Return a canonical path (i.e. the absolute location of a file on the
# filesystem).
def realpath(filename, *, strict=False):
def realpath(filename, /, *, strict=False):
"""Return the canonical path of the specified filename, eliminating any
symbolic links encountered in the path."""
filename = os.fspath(filename)