mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-31 16:44:25 +08:00
make os.path identical in Python 2 and 3 (#1459)
Part of #1427. I don't think we can actually merge these until we merge os/__init__.pyi too, which will take a few more PRs.
This commit is contained in:
committed by
Matthias Kramm
parent
7ecc979211
commit
a419b696d4
@@ -10,7 +10,12 @@ from typing import (
|
||||
)
|
||||
|
||||
_T = TypeVar('_T')
|
||||
_PathType = Union[bytes, Text]
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
from builtins import _PathLike
|
||||
_PathType = Union[bytes, Text, _PathLike]
|
||||
else:
|
||||
_PathType = Union[bytes, Text]
|
||||
|
||||
# ----- os.path variables -----
|
||||
supports_unicode_filenames = False
|
||||
@@ -55,20 +60,23 @@ def isdir(path: _PathType) -> bool: ...
|
||||
def islink(path: _PathType) -> bool: ...
|
||||
def ismount(path: _PathType) -> bool: ...
|
||||
|
||||
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
|
||||
# (Since Python 2 allows that, too)
|
||||
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
|
||||
# a type error.
|
||||
@overload
|
||||
def join(__p1: bytes, *p: bytes) -> bytes: ...
|
||||
@overload
|
||||
def join(__p1: Text, *p: _PathType) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
|
||||
if sys.version_info < (3, 0):
|
||||
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
|
||||
# (Since Python 2 allows that, too)
|
||||
# Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in
|
||||
# a type error.
|
||||
@overload
|
||||
def join(__p1: bytes, *p: bytes) -> bytes: ...
|
||||
@overload
|
||||
def join(__p1: Text, *p: _PathType) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
|
||||
else:
|
||||
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
|
||||
|
||||
def normcase(path: AnyStr) -> AnyStr: ...
|
||||
def normpath(path: AnyStr) -> AnyStr: ...
|
||||
|
||||
Reference in New Issue
Block a user