Skip to content

Commit 99cdf1d

Browse files
authored
gh-136437: Make several functions in os.path pos-only (#136949)
1 parent e41c1ce commit 99cdf1d

File tree

5 files changed

+51
-147
lines changed

5 files changed

+51
-147
lines changed

Lib/genericpath.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,28 @@ def isdevdrive(path):
8181
return False
8282

8383

84-
def getsize(filename):
84+
def getsize(filename, /):
8585
"""Return the size of a file, reported by os.stat()."""
8686
return os.stat(filename).st_size
8787

8888

89-
def getmtime(filename):
89+
def getmtime(filename, /):
9090
"""Return the last modification time of a file, reported by os.stat()."""
9191
return os.stat(filename).st_mtime
9292

9393

94-
def getatime(filename):
94+
def getatime(filename, /):
9595
"""Return the last access time of a file, reported by os.stat()."""
9696
return os.stat(filename).st_atime
9797

9898

99-
def getctime(filename):
99+
def getctime(filename, /):
100100
"""Return the metadata change time of a file, reported by os.stat()."""
101101
return os.stat(filename).st_ctime
102102

103103

104104
# Return the longest prefix of all list elements.
105-
def commonprefix(m):
105+
def commonprefix(m, /):
106106
"Given a list of pathnames, returns the longest common leading component"
107107
if not m: return ''
108108
# Some people pass in a list of pathname parts to operate in an OS-agnostic
@@ -120,14 +120,14 @@ def commonprefix(m):
120120

121121
# Are two stat buffers (obtained from stat, fstat or lstat)
122122
# describing the same file?
123-
def samestat(s1, s2):
123+
def samestat(s1, s2, /):
124124
"""Test whether two stat buffers reference the same file"""
125125
return (s1.st_ino == s2.st_ino and
126126
s1.st_dev == s2.st_dev)
127127

128128

129129
# Are two filenames really pointing to the same file?
130-
def samefile(f1, f2):
130+
def samefile(f1, f2, /):
131131
"""Test whether two pathnames reference the same actual file or directory
132132
133133
This is determined by the device number and i-node number and

Lib/ntpath.py

Lines changed: 12 additions & 12 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):
@@ -96,7 +96,7 @@ def isabs(s):
9696

9797

9898
# Join two (or more) paths.
99-
def join(path, *paths):
99+
def join(path, /, *paths):
100100
path = os.fspath(path)
101101
if isinstance(path, bytes):
102102
sep = 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-
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

@@ -601,7 +601,7 @@ def abspath(path):
601601
from nt import _findfirstfile, _getfinalpathname, readlink as _nt_readlink
602602
except ImportError:
603603
# realpath is a no-op on systems without _getfinalpathname support.
604-
def realpath(path, *, strict=False):
604+
def realpath(path, /, *, strict=False):
605605
return abspath(path)
606606
else:
607607
def _readlink_deep(path, ignored_error=OSError):
@@ -702,7 +702,7 @@ def _getfinalpathname_nonstrict(path, ignored_error=OSError):
702702
tail = join(name, tail) if tail else name
703703
return tail
704704

705-
def realpath(path, *, strict=False):
705+
def realpath(path, /, *, strict=False):
706706
path = normpath(path)
707707
if isinstance(path, bytes):
708708
prefix = b'\\\\?\\'

Lib/posixpath.py

Lines changed: 10 additions & 10 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)
@@ -69,7 +69,7 @@ def isabs(s):
6969
# Ignore the previous parts if a part is absolute.
7070
# Insert a '/' unless the first part is empty or already ends in '/'.
7171

72-
def join(a, *p):
72+
def join(a, /, *p):
7373
"""Join two or more pathname components, inserting '/' as needed.
7474
If any component is an absolute path, all previous path components
7575
will be discarded. An empty last part will result in a path that
@@ -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)
@@ -388,7 +388,7 @@ def abspath(path):
388388
# Return a canonical path (i.e. the absolute location of a file on the
389389
# filesystem).
390390

391-
def realpath(filename, *, strict=False):
391+
def realpath(filename, /, *, strict=False):
392392
"""Return the canonical path of the specified filename, eliminating any
393393
symbolic links encountered in the path."""
394394
filename = os.fspath(filename)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy