##// END OF EJS Templates
typing: add type hints to the posix platform module matching win32.py
Matt Harbison -
r50706:0a91aba2 default
parent child Browse files
Show More
@@ -19,6 +19,12 b' import sys'
19 import tempfile
19 import tempfile
20 import unicodedata
20 import unicodedata
21
21
22 from typing import (
23 List,
24 NoReturn,
25 Optional,
26 )
27
22 from .i18n import _
28 from .i18n import _
23 from .pycompat import (
29 from .pycompat import (
24 getattr,
30 getattr,
@@ -44,7 +50,7 b' except AttributeError:'
44 # vaguely unix-like but don't have hardlink support. For those
50 # vaguely unix-like but don't have hardlink support. For those
45 # poor souls, just say we tried and that it failed so we fall back
51 # poor souls, just say we tried and that it failed so we fall back
46 # to copies.
52 # to copies.
47 def oslink(src, dst):
53 def oslink(src: bytes, dst: bytes) -> NoReturn:
48 raise OSError(
54 raise OSError(
49 errno.EINVAL, b'hardlinks not supported: %s to %s' % (src, dst)
55 errno.EINVAL, b'hardlinks not supported: %s to %s' % (src, dst)
50 )
56 )
@@ -90,7 +96,7 b' def openhardlinks():'
90 return True
96 return True
91
97
92
98
93 def nlinks(name):
99 def nlinks(name: bytes) -> int:
94 '''return number of hardlinks for the given file'''
100 '''return number of hardlinks for the given file'''
95 return os.lstat(name).st_nlink
101 return os.lstat(name).st_nlink
96
102
@@ -348,7 +354,7 b' def getfsmountpoint(dirpath):'
348 return getattr(osutil, 'getfsmountpoint', lambda x: None)(dirpath)
354 return getattr(osutil, 'getfsmountpoint', lambda x: None)(dirpath)
349
355
350
356
351 def getfstype(dirpath):
357 def getfstype(dirpath: bytes) -> Optional[bytes]:
352 """Get the filesystem type name from a directory (best-effort)
358 """Get the filesystem type name from a directory (best-effort)
353
359
354 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
360 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
@@ -372,13 +378,13 b' def localpath(path):'
372 return path
378 return path
373
379
374
380
375 def samefile(fpath1, fpath2):
381 def samefile(fpath1: bytes, fpath2: bytes) -> bool:
376 """Returns whether path1 and path2 refer to the same file. This is only
382 """Returns whether path1 and path2 refer to the same file. This is only
377 guaranteed to work for files, not directories."""
383 guaranteed to work for files, not directories."""
378 return os.path.samefile(fpath1, fpath2)
384 return os.path.samefile(fpath1, fpath2)
379
385
380
386
381 def samedevice(fpath1, fpath2):
387 def samedevice(fpath1: bytes, fpath2: bytes) -> bool:
382 """Returns whether fpath1 and fpath2 are on the same device. This is only
388 """Returns whether fpath1 and fpath2 are on the same device. This is only
383 guaranteed to work for files, not directories."""
389 guaranteed to work for files, not directories."""
384 st1 = os.lstat(fpath1)
390 st1 = os.lstat(fpath1)
@@ -521,7 +527,7 b' def shellsplit(s):'
521 return pycompat.shlexsplit(s, posix=True)
527 return pycompat.shlexsplit(s, posix=True)
522
528
523
529
524 def testpid(pid):
530 def testpid(pid: int) -> bool:
525 '''return False if pid dead, True if running or not sure'''
531 '''return False if pid dead, True if running or not sure'''
526 if pycompat.sysplatform == b'OpenVMS':
532 if pycompat.sysplatform == b'OpenVMS':
527 return True
533 return True
@@ -564,7 +570,7 b' def findexe(command):'
564 return None
570 return None
565
571
566
572
567 def setsignalhandler():
573 def setsignalhandler() -> None:
568 pass
574 pass
569
575
570
576
@@ -586,7 +592,7 b' def statfiles(files):'
586 yield st
592 yield st
587
593
588
594
589 def getuser():
595 def getuser() -> bytes:
590 '''return name of current user'''
596 '''return name of current user'''
591 return pycompat.fsencode(getpass.getuser())
597 return pycompat.fsencode(getpass.getuser())
592
598
@@ -625,7 +631,7 b' def groupmembers(name):'
625 return pycompat.rapply(pycompat.fsencode, list(grp.getgrnam(name).gr_mem))
631 return pycompat.rapply(pycompat.fsencode, list(grp.getgrnam(name).gr_mem))
626
632
627
633
628 def spawndetached(args) -> int:
634 def spawndetached(args: List[bytes]) -> int:
629 return os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), args[0], args)
635 return os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), args[0], args)
630
636
631
637
@@ -633,7 +639,7 b' def gethgcmd():'
633 return sys.argv[:1]
639 return sys.argv[:1]
634
640
635
641
636 def makedir(path, notindexed):
642 def makedir(path: bytes, notindexed: bool) -> None:
637 os.mkdir(path)
643 os.mkdir(path)
638
644
639
645
@@ -641,7 +647,7 b' def lookupreg(key, name=None, scope=None'
641 return None
647 return None
642
648
643
649
644 def hidewindow():
650 def hidewindow() -> None:
645 """Hide current shell window.
651 """Hide current shell window.
646
652
647 Used to hide the window opened when starting asynchronous
653 Used to hide the window opened when starting asynchronous
General Comments 0
You need to be logged in to leave comments. Login now