##// END OF EJS Templates
typing: add trivial type hints to rest of the windows platform module...
Matt Harbison -
r50712:2b147671 default
parent child Browse files
Show More
@@ -17,12 +17,15 b' import sys'
17 import winreg # pytype: disable=import-error
17 import winreg # pytype: disable=import-error
18
18
19 from typing import (
19 from typing import (
20 AnyStr,
20 BinaryIO,
21 BinaryIO,
21 Iterable,
22 Iterable,
22 Iterator,
23 Iterator,
23 List,
24 List,
25 Mapping,
24 NoReturn,
26 NoReturn,
25 Optional,
27 Optional,
28 Pattern,
26 Sequence,
29 Sequence,
27 Union,
30 Union,
28 )
31 )
@@ -56,7 +59,7 b' split = os.path.split'
56 testpid = win32.testpid
59 testpid = win32.testpid
57 unlink = win32.unlink
60 unlink = win32.unlink
58
61
59 umask = 0o022
62 umask: int = 0o022
60
63
61
64
62 class mixedfilemodewrapper:
65 class mixedfilemodewrapper:
@@ -317,7 +320,7 b' def localpath(path: bytes) -> bytes:'
317 return path.replace(b'/', b'\\')
320 return path.replace(b'/', b'\\')
318
321
319
322
320 def normpath(path):
323 def normpath(path: bytes) -> bytes:
321 return pconvert(os.path.normpath(path))
324 return pconvert(os.path.normpath(path))
322
325
323
326
@@ -325,11 +328,12 b' def normcase(path: bytes) -> bytes:'
325 return encoding.upper(path) # NTFS compares via upper()
328 return encoding.upper(path) # NTFS compares via upper()
326
329
327
330
328 DRIVE_RE_B = re.compile(b'^[a-z]:')
331 DRIVE_RE_B: Pattern[bytes] = re.compile(b'^[a-z]:')
329 DRIVE_RE_S = re.compile('^[a-z]:')
332 DRIVE_RE_S: Pattern[str] = re.compile('^[a-z]:')
330
333
331
334
332 def abspath(path):
335 # TODO: why is this accepting str?
336 def abspath(path: AnyStr) -> AnyStr:
333 abs_path = os.path.abspath(path) # re-exports
337 abs_path = os.path.abspath(path) # re-exports
334 # Python on Windows is inconsistent regarding the capitalization of drive
338 # Python on Windows is inconsistent regarding the capitalization of drive
335 # letter and this cause issue with various path comparison along the way.
339 # letter and this cause issue with various path comparison along the way.
@@ -345,15 +349,15 b' def abspath(path):'
345
349
346
350
347 # see posix.py for definitions
351 # see posix.py for definitions
348 normcasespec = encoding.normcasespecs.upper
352 normcasespec: int = encoding.normcasespecs.upper
349 normcasefallback = encoding.upperfallback
353 normcasefallback = encoding.upperfallback
350
354
351
355
352 def samestat(s1, s2):
356 def samestat(s1: os.stat_result, s2: os.stat_result) -> bool:
353 return False
357 return False
354
358
355
359
356 def shelltocmdexe(path, env):
360 def shelltocmdexe(path: bytes, env: Mapping[bytes, bytes]) -> bytes:
357 r"""Convert shell variables in the form $var and ${var} inside ``path``
361 r"""Convert shell variables in the form $var and ${var} inside ``path``
358 to %var% form. Existing Windows style variables are left unchanged.
362 to %var% form. Existing Windows style variables are left unchanged.
359
363
@@ -478,7 +482,7 b' def shelltocmdexe(path, env):'
478 # the number of backslashes that precede double quotes and add another
482 # the number of backslashes that precede double quotes and add another
479 # backslash before every double quote (being careful with the double
483 # backslash before every double quote (being careful with the double
480 # quote we've appended to the end)
484 # quote we've appended to the end)
481 _quotere = None
485 _quotere: Optional[Pattern[bytes]] = None
482 _needsshellquote = None
486 _needsshellquote = None
483
487
484
488
@@ -512,7 +516,7 b' def shellquote(s: bytes) -> bytes:'
512 return b'"%s"' % _quotere.sub(br'\1\1\\\2', s)
516 return b'"%s"' % _quotere.sub(br'\1\1\\\2', s)
513
517
514
518
515 def _unquote(s):
519 def _unquote(s: bytes) -> bytes:
516 if s.startswith(b'"') and s.endswith(b'"'):
520 if s.startswith(b'"') and s.endswith(b'"'):
517 return s[1:-1]
521 return s[1:-1]
518 return s
522 return s
@@ -609,7 +613,7 b' def groupname(gid: Optional[int] = None)'
609 return None
613 return None
610
614
611
615
612 def readlink(pathname):
616 def readlink(pathname: bytes) -> bytes:
613 path = pycompat.fsdecode(pathname)
617 path = pycompat.fsdecode(pathname)
614 try:
618 try:
615 link = os.readlink(path)
619 link = os.readlink(path)
@@ -622,7 +626,7 b' def readlink(pathname):'
622 return pycompat.fsencode(link)
626 return pycompat.fsencode(link)
623
627
624
628
625 def removedirs(name):
629 def removedirs(name: bytes) -> None:
626 """special version of os.removedirs that does not remove symlinked
630 """special version of os.removedirs that does not remove symlinked
627 directories or junction points if they actually contain files"""
631 directories or junction points if they actually contain files"""
628 if listdir(name):
632 if listdir(name):
@@ -641,7 +645,7 b' def removedirs(name):'
641 head, tail = os.path.split(head)
645 head, tail = os.path.split(head)
642
646
643
647
644 def rename(src, dst):
648 def rename(src: bytes, dst: bytes) -> None:
645 '''atomically rename file src to dst, replacing dst if it exists'''
649 '''atomically rename file src to dst, replacing dst if it exists'''
646 try:
650 try:
647 os.rename(src, dst)
651 os.rename(src, dst)
@@ -650,7 +654,7 b' def rename(src, dst):'
650 os.rename(src, dst)
654 os.rename(src, dst)
651
655
652
656
653 def gethgcmd():
657 def gethgcmd() -> List[bytes]:
654 return [encoding.strtolocal(arg) for arg in [sys.executable] + sys.argv[:1]]
658 return [encoding.strtolocal(arg) for arg in [sys.executable] + sys.argv[:1]]
655
659
656
660
@@ -708,7 +712,7 b' def lookupreg('
708 pass
712 pass
709
713
710
714
711 expandglobs = True
715 expandglobs: bool = True
712
716
713
717
714 def statislink(st: Optional[os.stat_result]) -> bool:
718 def statislink(st: Optional[os.stat_result]) -> bool:
@@ -721,7 +725,7 b' def statisexec(st: Optional[os.stat_resu'
721 return False
725 return False
722
726
723
727
724 def poll(fds):
728 def poll(fds) -> List:
725 # see posix.py for description
729 # see posix.py for description
726 raise NotImplementedError()
730 raise NotImplementedError()
727
731
General Comments 0
You need to be logged in to leave comments. Login now