Akuli and srittau: Remove Python 2 branches from Python 3 stubs (#5461)

* run script and do some manual changes (Akuli)

* do the whole thing manually (srittau)

* merge changes (Akuli)

Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
This commit is contained in:
Akuli
2021-05-15 15:33:39 +03:00
committed by GitHub
parent b0ef85288d
commit 17dcea4a68
106 changed files with 1539 additions and 3275 deletions

View File

@@ -1,4 +1,3 @@
import sys
from _typeshed import AnyPath, BytesPath, StrPath
from genericpath import (
commonprefix as commonprefix,
@@ -9,10 +8,11 @@ from genericpath import (
getsize as getsize,
isdir as isdir,
isfile as isfile,
samefile as samefile,
sameopenfile as sameopenfile,
samestat as samestat,
)
if sys.version_info >= (3, 4):
from genericpath import samefile as samefile, sameopenfile as sameopenfile, samestat as samestat
from os import PathLike
# Re-export common definitions from posixpath to reduce duplication
from posixpath import (
@@ -36,69 +36,34 @@ from typing import AnyStr, Optional, Text, Tuple, overload
altsep: Optional[str]
if sys.version_info >= (3, 6):
from os import PathLike
@overload
def basename(s: PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(s: AnyStr) -> AnyStr: ...
@overload
def dirname(s: PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(s: AnyStr) -> AnyStr: ...
@overload
def normcase(path: PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(s: PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(s: AnyStr) -> AnyStr: ...
@overload
def realpath(path: PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
else:
def basename(s: AnyStr) -> AnyStr: ...
def dirname(s: AnyStr) -> AnyStr: ...
def normcase(path: AnyStr) -> AnyStr: ...
def normpath(s: AnyStr) -> AnyStr: ...
def realpath(path: AnyStr) -> AnyStr: ...
@overload
def basename(s: PathLike[AnyStr]) -> AnyStr: ...
@overload
def basename(s: AnyStr) -> AnyStr: ...
@overload
def dirname(s: PathLike[AnyStr]) -> AnyStr: ...
@overload
def dirname(s: AnyStr) -> AnyStr: ...
@overload
def normcase(path: PathLike[AnyStr]) -> AnyStr: ...
@overload
def normcase(path: AnyStr) -> AnyStr: ...
@overload
def normpath(s: PathLike[AnyStr]) -> AnyStr: ...
@overload
def normpath(s: AnyStr) -> AnyStr: ...
@overload
def realpath(path: PathLike[AnyStr]) -> AnyStr: ...
@overload
def realpath(path: AnyStr) -> AnyStr: ...
def islink(s: AnyPath) -> bool: ...
if sys.version_info >= (3, 6):
# Mypy complains that the signatures overlap, but things seem to behave correctly anyway.
@overload
def join(s: StrPath, *paths: StrPath) -> Text: ...
@overload
def join(s: BytesPath, *paths: BytesPath) -> bytes: ...
elif sys.version_info >= (3, 0):
def join(s: AnyStr, *paths: AnyStr) -> AnyStr: ...
else:
# 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: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: AnyPath) -> Text: ...
@overload
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: AnyPath) -> Text: ...
@overload
def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ...
@overload
def join(__p1: Text, *p: AnyPath) -> Text: ...
if sys.version_info >= (3, 6):
@overload
def split(s: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
else:
def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
# Mypy complains that the signatures overlap, but things seem to behave correctly anyway.
@overload
def join(s: StrPath, *paths: StrPath) -> Text: ...
@overload
def join(s: BytesPath, *paths: BytesPath) -> bytes: ...
@overload
def split(s: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
@overload
def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ...