mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
fix types in os.path (#1363)
In Python 2, doing
os.path.join(u"foo", "bar")
is actually legal, and returns a unicode string.
Also os.path.relpath always returns the type of its first argument.
(The solution is not perfect -- e.g.
os.path.join("a", "b", "c", "d", u"e")
will still result in a type error. )
This commit is contained in:
committed by
Guido van Rossum
parent
2b79108ddc
commit
6f07424246
@@ -55,7 +55,20 @@ def isdir(path: _PathType) -> bool: ...
|
||||
def islink(path: _PathType) -> bool: ...
|
||||
def ismount(path: _PathType) -> bool: ...
|
||||
|
||||
def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ...
|
||||
# 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: ...
|
||||
|
||||
def normcase(path: AnyStr) -> AnyStr: ...
|
||||
def normpath(path: AnyStr) -> AnyStr: ...
|
||||
@@ -63,7 +76,7 @@ if sys.platform == 'win32':
|
||||
def realpath(path: AnyStr) -> AnyStr: ...
|
||||
else:
|
||||
def realpath(filename: AnyStr) -> AnyStr: ...
|
||||
def relpath(path: AnyStr, start: AnyStr = ...) -> AnyStr: ...
|
||||
def relpath(path: AnyStr, start: _PathType = ...) -> AnyStr: ...
|
||||
|
||||
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
|
||||
def sameopenfile(fp1: int, fp2: int) -> bool: ...
|
||||
|
||||
Reference in New Issue
Block a user