Skip to content
Snippets Groups Projects
Commit 2b147671 authored by Matt Harbison's avatar Matt Harbison
Browse files

typing: add trivial type hints to rest of the windows platform module

Skipping the file wrappers for now because there's interplay with C code, and
making them subclass `typing.BinaryIO_Proxy` confuses PyCharm a bit.
parent ae93ada0
No related branches found
No related tags found
2 merge requests!485branching: merge default into stable,!357Add type hints to platform modules
......@@ -17,7 +17,8 @@
import winreg # pytype: disable=import-error
from typing import (
AnyStr,
BinaryIO,
Iterable,
Iterator,
List,
......@@ -20,6 +21,7 @@
BinaryIO,
Iterable,
Iterator,
List,
Mapping,
NoReturn,
Optional,
......@@ -24,5 +26,6 @@
NoReturn,
Optional,
Pattern,
Sequence,
Union,
)
......@@ -56,7 +59,7 @@
testpid = win32.testpid
unlink = win32.unlink
umask = 0o022
umask: int = 0o022
class mixedfilemodewrapper:
......@@ -317,7 +320,7 @@
return path.replace(b'/', b'\\')
def normpath(path):
def normpath(path: bytes) -> bytes:
return pconvert(os.path.normpath(path))
......@@ -325,7 +328,7 @@
return encoding.upper(path) # NTFS compares via upper()
DRIVE_RE_B = re.compile(b'^[a-z]:')
DRIVE_RE_S = re.compile('^[a-z]:')
DRIVE_RE_B: Pattern[bytes] = re.compile(b'^[a-z]:')
DRIVE_RE_S: Pattern[str] = re.compile('^[a-z]:')
......@@ -330,6 +333,7 @@
def abspath(path):
# TODO: why is this accepting str?
def abspath(path: AnyStr) -> AnyStr:
abs_path = os.path.abspath(path) # re-exports
# Python on Windows is inconsistent regarding the capitalization of drive
# letter and this cause issue with various path comparison along the way.
......@@ -345,7 +349,7 @@
# see posix.py for definitions
normcasespec = encoding.normcasespecs.upper
normcasespec: int = encoding.normcasespecs.upper
normcasefallback = encoding.upperfallback
......@@ -349,7 +353,7 @@
normcasefallback = encoding.upperfallback
def samestat(s1, s2):
def samestat(s1: os.stat_result, s2: os.stat_result) -> bool:
return False
......@@ -353,7 +357,7 @@
return False
def shelltocmdexe(path, env):
def shelltocmdexe(path: bytes, env: Mapping[bytes, bytes]) -> bytes:
r"""Convert shell variables in the form $var and ${var} inside ``path``
to %var% form. Existing Windows style variables are left unchanged.
......@@ -478,7 +482,7 @@
# the number of backslashes that precede double quotes and add another
# backslash before every double quote (being careful with the double
# quote we've appended to the end)
_quotere = None
_quotere: Optional[Pattern[bytes]] = None
_needsshellquote = None
......@@ -512,7 +516,7 @@
return b'"%s"' % _quotere.sub(br'\1\1\\\2', s)
def _unquote(s):
def _unquote(s: bytes) -> bytes:
if s.startswith(b'"') and s.endswith(b'"'):
return s[1:-1]
return s
......@@ -609,7 +613,7 @@
return None
def readlink(pathname):
def readlink(pathname: bytes) -> bytes:
path = pycompat.fsdecode(pathname)
try:
link = os.readlink(path)
......@@ -622,7 +626,7 @@
return pycompat.fsencode(link)
def removedirs(name):
def removedirs(name: bytes) -> None:
"""special version of os.removedirs that does not remove symlinked
directories or junction points if they actually contain files"""
if listdir(name):
......@@ -641,7 +645,7 @@
head, tail = os.path.split(head)
def rename(src, dst):
def rename(src: bytes, dst: bytes) -> None:
'''atomically rename file src to dst, replacing dst if it exists'''
try:
os.rename(src, dst)
......@@ -650,7 +654,7 @@
os.rename(src, dst)
def gethgcmd():
def gethgcmd() -> List[bytes]:
return [encoding.strtolocal(arg) for arg in [sys.executable] + sys.argv[:1]]
......@@ -708,7 +712,7 @@
pass
expandglobs = True
expandglobs: bool = True
def statislink(st: Optional[os.stat_result]) -> bool:
......@@ -721,7 +725,7 @@
return False
def poll(fds):
def poll(fds) -> List:
# see posix.py for description
raise NotImplementedError()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment