mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
Add LiteralString overloads to path module (#7727)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import BytesPath, StrOrBytesPath, StrPath
|
||||
from _typeshed import AnyOrLiteralStr, BytesPath, StrOrBytesPath, StrPath
|
||||
from collections.abc import Sequence
|
||||
from genericpath import (
|
||||
commonprefix as commonprefix,
|
||||
@@ -16,6 +16,7 @@ from genericpath import (
|
||||
)
|
||||
from os import PathLike
|
||||
from typing import AnyStr, overload
|
||||
from typing_extensions import LiteralString
|
||||
|
||||
__all__ = [
|
||||
"normcase",
|
||||
@@ -60,14 +61,14 @@ __all__ = [
|
||||
|
||||
supports_unicode_filenames: bool
|
||||
# aliases (also in os)
|
||||
curdir: str
|
||||
pardir: str
|
||||
sep: str
|
||||
altsep: str | None
|
||||
extsep: str
|
||||
pathsep: str
|
||||
defpath: str
|
||||
devnull: str
|
||||
curdir: LiteralString
|
||||
pardir: LiteralString
|
||||
sep: LiteralString
|
||||
altsep: LiteralString | None
|
||||
extsep: LiteralString
|
||||
pathsep: LiteralString
|
||||
defpath: LiteralString
|
||||
devnull: LiteralString
|
||||
|
||||
# Overloads are necessary to work around python/mypy#3644.
|
||||
@overload
|
||||
@@ -77,11 +78,11 @@ def abspath(path: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def basename(p: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def basename(p: AnyStr) -> AnyStr: ...
|
||||
def basename(p: AnyOrLiteralStr) -> AnyOrLiteralStr: ...
|
||||
@overload
|
||||
def dirname(p: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def dirname(p: AnyStr) -> AnyStr: ...
|
||||
def dirname(p: AnyOrLiteralStr) -> AnyOrLiteralStr: ...
|
||||
@overload
|
||||
def expanduser(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
@@ -93,11 +94,13 @@ def expandvars(path: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def normcase(s: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def normcase(s: AnyStr) -> AnyStr: ...
|
||||
def normcase(s: AnyOrLiteralStr) -> AnyOrLiteralStr: ...
|
||||
@overload
|
||||
def normpath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def normpath(path: AnyStr) -> AnyStr: ...
|
||||
def normpath(path: AnyOrLiteralStr) -> AnyOrLiteralStr: ...
|
||||
@overload
|
||||
def commonpath(paths: Sequence[LiteralString]) -> LiteralString: ...
|
||||
@overload
|
||||
def commonpath(paths: Sequence[StrPath]) -> str: ...
|
||||
@overload
|
||||
@@ -107,6 +110,8 @@ def commonpath(paths: Sequence[BytesPath]) -> bytes: ...
|
||||
# but must be defined as pos-only in the stub or cross-platform code doesn't type-check,
|
||||
# as the parameter name is different in ntpath.join()
|
||||
@overload
|
||||
def join(__a: LiteralString, *paths: LiteralString) -> LiteralString: ...
|
||||
@overload
|
||||
def join(__a: StrPath, *paths: StrPath) -> str: ...
|
||||
@overload
|
||||
def join(__a: BytesPath, *paths: BytesPath) -> bytes: ...
|
||||
@@ -123,6 +128,8 @@ else:
|
||||
@overload
|
||||
def realpath(filename: AnyStr) -> AnyStr: ...
|
||||
|
||||
@overload
|
||||
def relpath(path: LiteralString, start: LiteralString | None = ...) -> LiteralString: ...
|
||||
@overload
|
||||
def relpath(path: BytesPath, start: BytesPath | None = ...) -> bytes: ...
|
||||
@overload
|
||||
@@ -130,15 +137,15 @@ def relpath(path: StrPath, start: StrPath | None = ...) -> str: ...
|
||||
@overload
|
||||
def split(p: PathLike[AnyStr]) -> tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def split(p: AnyStr) -> tuple[AnyStr, AnyStr]: ...
|
||||
def split(p: AnyOrLiteralStr) -> tuple[AnyOrLiteralStr, AnyOrLiteralStr]: ...
|
||||
@overload
|
||||
def splitdrive(p: PathLike[AnyStr]) -> tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitdrive(p: AnyStr) -> tuple[AnyStr, AnyStr]: ...
|
||||
def splitdrive(p: AnyOrLiteralStr) -> tuple[AnyOrLiteralStr, AnyOrLiteralStr]: ...
|
||||
@overload
|
||||
def splitext(p: PathLike[AnyStr]) -> tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitext(p: AnyStr) -> tuple[AnyStr, AnyStr]: ...
|
||||
def splitext(p: AnyOrLiteralStr) -> tuple[AnyOrLiteralStr, AnyOrLiteralStr]: ...
|
||||
def isabs(s: StrOrBytesPath) -> bool: ...
|
||||
def islink(path: StrOrBytesPath | int) -> bool: ...
|
||||
def ismount(path: StrOrBytesPath | int) -> bool: ...
|
||||
|
||||
Reference in New Issue
Block a user