Format: application/octet-stream
⬇ Download File (5.2 KB)
   1  import os
   2  import sys
   3  from _typeshed import AnyPath, BytesPath, StrPath
   4  from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, Union, overload
   5  
   6  if sys.version_info < (3, 8):
   7      _T = TypeVar("_T")
   8  
   9      if sys.version_info >= (3, 6):
  10          from builtins import _PathLike
  11  
  12      # ----- os.path variables -----
  13      supports_unicode_filenames: bool
  14      # aliases (also in os)
  15      curdir: str
  16      pardir: str
  17      sep: str
  18      altsep: Optional[str]
  19      extsep: str
  20      pathsep: str
  21      defpath: str
  22      devnull: str
  23  
  24      # ----- os.path function stubs -----
  25      if sys.version_info >= (3, 6):
  26          # Overloads are necessary to work around python/mypy#3644.
  27          @overload
  28          def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
  29          @overload
  30          def abspath(path: AnyStr) -> AnyStr: ...
  31          @overload
  32          def basename(s: _PathLike[AnyStr]) -> AnyStr: ...
  33          @overload
  34          def basename(s: AnyStr) -> AnyStr: ...
  35          @overload
  36          def dirname(s: _PathLike[AnyStr]) -> AnyStr: ...
  37          @overload
  38          def dirname(s: AnyStr) -> AnyStr: ...
  39          @overload
  40          def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
  41          @overload
  42          def expanduser(path: AnyStr) -> AnyStr: ...
  43          @overload
  44          def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
  45          @overload
  46          def expandvars(path: AnyStr) -> AnyStr: ...
  47          @overload
  48          def normcase(path: _PathLike[AnyStr]) -> AnyStr: ...
  49          @overload
  50          def normcase(path: AnyStr) -> AnyStr: ...
  51          @overload
  52          def normpath(s: _PathLike[AnyStr]) -> AnyStr: ...
  53          @overload
  54          def normpath(s: AnyStr) -> AnyStr: ...
  55          @overload
  56          def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
  57          @overload
  58          def realpath(path: AnyStr) -> AnyStr: ...
  59      else:
  60          def abspath(path: AnyStr) -> AnyStr: ...
  61          def basename(s: AnyStr) -> AnyStr: ...
  62          def dirname(s: AnyStr) -> AnyStr: ...
  63          def expanduser(path: AnyStr) -> AnyStr: ...
  64          def expandvars(path: AnyStr) -> AnyStr: ...
  65          def normcase(path: AnyStr) -> AnyStr: ...
  66          def normpath(s: AnyStr) -> AnyStr: ...
  67          def realpath(path: AnyStr) -> AnyStr: ...
  68      # NOTE: Empty lists results in '' (str) regardless of contained type.
  69      # Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
  70      # So, fall back to Any
  71      def commonprefix(m: Sequence[AnyPath]) -> Any: ...
  72      if sys.version_info >= (3, 3):
  73          def exists(path: Union[AnyPath, int]) -> bool: ...
  74      else:
  75          def exists(path: AnyPath) -> bool: ...
  76      def lexists(path: AnyPath) -> bool: ...
  77      # These return float if os.stat_float_times() == True,
  78      # but int is a subclass of float.
  79      def getatime(filename: AnyPath) -> float: ...
  80      def getmtime(filename: AnyPath) -> float: ...
  81      def getctime(filename: AnyPath) -> float: ...
  82      def getsize(filename: AnyPath) -> int: ...
  83      def isabs(s: AnyPath) -> bool: ...
  84      def isfile(path: AnyPath) -> bool: ...
  85      def isdir(s: AnyPath) -> bool: ...
  86      def islink(s: AnyPath) -> bool: ...
  87      def ismount(s: AnyPath) -> bool: ...
  88      if sys.version_info < (3, 0):
  89          # Make sure signatures are disjunct, and allow combinations of bytes and unicode.
  90          # (Since Python 2 allows that, too)
  91          # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
  92          # a type error.
  93          @overload
  94          def join(__p1: bytes, *p: bytes) -> bytes: ...
  95          @overload
  96          def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: AnyPath) -> Text: ...
  97          @overload
  98          def join(__p1: bytes, __p2: bytes, __p3: Text, *p: AnyPath) -> Text: ...
  99          @overload
 100          def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ...
 101          @overload
 102          def join(__p1: Text, *p: AnyPath) -> Text: ...
 103      elif sys.version_info >= (3, 6):
 104          # Mypy complains that the signatures overlap, but things seem to behave correctly anyway.
 105          @overload
 106          def join(s: StrPath, *paths: StrPath) -> Text: ...
 107          @overload
 108          def join(s: BytesPath, *paths: BytesPath) -> bytes: ...
 109      else:
 110          def join(s: AnyStr, *paths: AnyStr) -> AnyStr: ...
 111      def samefile(f1: AnyPath, f2: AnyPath) -> bool: ...
 112      def sameopenfile(fp1: int, fp2: int) -> bool: ...
 113      def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ...
 114      if sys.version_info >= (3, 6):
 115          @overload
 116          def split(s: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
 117          @overload
 118          def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
 119          @overload
 120          def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
 121          @overload
 122          def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
 123          @overload
 124          def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
 125          @overload
 126          def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
 127      else:
 128          def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
 129          def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
 130          def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
 131      if sys.version_info < (3,):
 132          def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ...
 133