typing: avoid some useless @overload definitions in `mercurial.util`
Apparently pytype considered the name as well as the type of each argument, and
generates @overload definitions if they don't match. At best this is clutter,
and can easily be removed.
--- a/mercurial/posix.py Thu Jul 18 22:46:36 2024 -0400
+++ b/mercurial/posix.py Fri Jul 19 16:38:53 2024 -0400
@@ -386,20 +386,20 @@
return None # on posix platforms, every path is ok
-def getfsmountpoint(dirpath: bytes) -> Optional[bytes]:
+def getfsmountpoint(path: bytes) -> Optional[bytes]:
"""Get the filesystem mount point from a directory (best-effort)
Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
"""
- return getattr(osutil, 'getfsmountpoint', lambda x: None)(dirpath)
+ return getattr(osutil, 'getfsmountpoint', lambda x: None)(path)
-def getfstype(dirpath: bytes) -> Optional[bytes]:
+def getfstype(path: bytes) -> Optional[bytes]:
"""Get the filesystem type name from a directory (best-effort)
Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
"""
- return getattr(osutil, 'getfstype', lambda x: None)(dirpath)
+ return getattr(osutil, 'getfstype', lambda x: None)(path)
def get_password() -> bytes:
@@ -691,7 +691,7 @@
def lookupreg(
key: bytes,
- name: Optional[bytes] = None,
+ valname: Optional[bytes] = None,
scope: Optional[Union[int, Iterable[int]]] = None,
) -> Optional[bytes]:
return None
--- a/mercurial/win32.py Thu Jul 18 22:46:36 2024 -0400
+++ b/mercurial/win32.py Fri Jul 19 16:38:53 2024 -0400
@@ -460,10 +460,10 @@
return _getfileinfo(name).nNumberOfLinks
-def samefile(path1: bytes, path2: bytes) -> bool:
- '''Returns whether path1 and path2 refer to the same file or directory.'''
- res1 = _getfileinfo(path1)
- res2 = _getfileinfo(path2)
+def samefile(fpath1: bytes, fpath2: bytes) -> bool:
+ '''Returns whether fpath1 and fpath2 refer to the same file or directory.'''
+ res1 = _getfileinfo(fpath1)
+ res2 = _getfileinfo(fpath2)
return (
res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber
and res1.nFileIndexHigh == res2.nFileIndexHigh
@@ -471,10 +471,10 @@
)
-def samedevice(path1: bytes, path2: bytes) -> bool:
- '''Returns whether path1 and path2 are on the same device.'''
- res1 = _getfileinfo(path1)
- res2 = _getfileinfo(path2)
+def samedevice(fpath1: bytes, fpath2: bytes) -> bool:
+ '''Returns whether fpath1 and fpath2 are on the same device.'''
+ res1 = _getfileinfo(fpath1)
+ res2 = _getfileinfo(fpath2)
return res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber
@@ -711,16 +711,16 @@
return pi.dwProcessId
-def unlink(f: bytes) -> None:
+def unlink(path: bytes) -> None:
'''try to implement POSIX' unlink semantics on Windows'''
- if os.path.isdir(f):
+ if os.path.isdir(path):
# use EPERM because it is POSIX prescribed value, even though
# unlink(2) on directories returns EISDIR on Linux
raise IOError(
errno.EPERM,
r"Unlinking directory not permitted: '%s'"
- % encoding.strfromlocal(f),
+ % encoding.strfromlocal(path),
)
# POSIX allows to unlink and rename open files. Windows has serious
@@ -741,9 +741,9 @@
# implicit zombie filename blocking on a temporary name.
for tries in range(10):
- temp = b'%s-%08x' % (f, random.randint(0, 0xFFFFFFFF))
+ temp = b'%s-%08x' % (path, random.randint(0, 0xFFFFFFFF))
try:
- os.rename(f, temp)
+ os.rename(path, temp)
break
except FileExistsError:
pass
--- a/mercurial/windows.py Thu Jul 18 22:46:36 2024 -0400
+++ b/mercurial/windows.py Fri Jul 19 16:38:53 2024 -0400
@@ -620,10 +620,10 @@
return None
-def readlink(pathname: bytes) -> bytes:
- path = pycompat.fsdecode(pathname)
+def readlink(path: bytes) -> bytes:
+ path_str = pycompat.fsdecode(path)
try:
- link = os.readlink(path)
+ link = os.readlink(path_str)
except ValueError as e:
# On py2, os.readlink() raises an AttributeError since it is
# unsupported. On py3, reading a non-link raises a ValueError. Simply