mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-16 08:47:39 +08:00
AnyStr cleanup (#5487)
* Replace all uses of StrPath, BytesPath, and AnyPath in Python 2 stubs. * Add StrOrBytesPath as preferred alias for AnyPath. * Replace all remaining AnyPath instances with StrOrBytesPath. * Mark AnyPath as obsolete. Part of #5470
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from _typeshed import AnyPath
|
||||
from _typeshed import StrOrBytesPath
|
||||
from typing import IO, Any, Callable, Iterable, Optional, Protocol, Text, TypeVar, Union
|
||||
from typing_extensions import Literal
|
||||
|
||||
@@ -36,7 +36,7 @@ def select_autoescape(
|
||||
def consume(iterable: Iterable[object]) -> None: ...
|
||||
def clear_caches() -> None: ...
|
||||
def import_string(import_name: str, silent: bool = ...) -> Any: ...
|
||||
def open_if_exists(filename: AnyPath, mode: str = ...) -> Optional[IO[Any]]: ...
|
||||
def open_if_exists(filename: StrOrBytesPath, mode: str = ...) -> Optional[IO[Any]]: ...
|
||||
def object_type_repr(obj: object) -> str: ...
|
||||
def pformat(obj: object, verbose: bool = ...) -> str: ...
|
||||
def urlize(
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import sys
|
||||
from _typeshed import AnyPath
|
||||
from _typeshed import StrOrBytesPath
|
||||
from os import stat_result
|
||||
from typing import Optional, Sequence, Union, overload
|
||||
|
||||
_FdOrAnyPath = Union[int, AnyPath]
|
||||
_FdOrAnyPath = Union[int, StrOrBytesPath]
|
||||
|
||||
async def stat(path: _FdOrAnyPath, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> stat_result: ...
|
||||
async def rename(src: AnyPath, dst: AnyPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ...
|
||||
async def remove(path: AnyPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
async def mkdir(path: AnyPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
async def rmdir(path: AnyPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
async def rename(
|
||||
src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...
|
||||
) -> None: ...
|
||||
async def remove(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
async def mkdir(path: StrOrBytesPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
async def rmdir(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
@overload
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
from _typeshed import AnyPath, OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode
|
||||
from _typeshed import (
|
||||
OpenBinaryMode,
|
||||
OpenBinaryModeReading,
|
||||
OpenBinaryModeUpdating,
|
||||
OpenBinaryModeWriting,
|
||||
OpenTextMode,
|
||||
StrOrBytesPath,
|
||||
)
|
||||
from asyncio import AbstractEventLoop
|
||||
from typing import Any, Callable, Optional, Union, overload
|
||||
from typing_extensions import Literal
|
||||
@@ -7,7 +14,7 @@ from ..base import AiofilesContextManager
|
||||
from .binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO, _UnknownAsyncBinaryIO
|
||||
from .text import AsyncTextIOWrapper
|
||||
|
||||
_OpenFile = Union[AnyPath, int]
|
||||
_OpenFile = Union[StrOrBytesPath, int]
|
||||
_Opener = Callable[[str, int], int]
|
||||
|
||||
# Text mode: always returns AsyncTextIOWrapper
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from _typeshed import AnyPath, ReadableBuffer, WriteableBuffer
|
||||
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
|
||||
from io import FileIO
|
||||
from typing import Iterable, List, Optional, Union
|
||||
|
||||
@@ -26,7 +26,7 @@ class _UnknownAsyncBinaryIO(AsyncBase[bytes]):
|
||||
@property
|
||||
def mode(self) -> str: ...
|
||||
@property
|
||||
def name(self) -> Union[AnyPath, int]: ...
|
||||
def name(self) -> Union[StrOrBytesPath, int]: ...
|
||||
|
||||
class AsyncBufferedIOBase(_UnknownAsyncBinaryIO):
|
||||
async def read1(self, __size: int = ...) -> bytes: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from _typeshed import AnyPath
|
||||
from _typeshed import StrOrBytesPath
|
||||
from typing import BinaryIO, Iterable, List, Optional, Tuple, Union
|
||||
|
||||
from ..base import AsyncBase
|
||||
@@ -33,6 +33,6 @@ class AsyncTextIOWrapper(AsyncBase[str]):
|
||||
@property
|
||||
def newlines(self) -> Union[str, Tuple[str, ...], None]: ...
|
||||
@property
|
||||
def name(self) -> Union[AnyPath, int]: ...
|
||||
def name(self) -> Union[StrOrBytesPath, int]: ...
|
||||
@property
|
||||
def mode(self) -> str: ...
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
from _typeshed import AnyPath
|
||||
from _typeshed import StrOrBytesPath
|
||||
from typing import IO, Any, AnyStr, Callable, ContextManager, Optional, Text, Type
|
||||
|
||||
def replace_atomic(src: AnyStr, dst: AnyStr) -> None: ...
|
||||
def move_atomic(src: AnyStr, dst: AnyStr) -> None: ...
|
||||
|
||||
class AtomicWriter(object):
|
||||
def __init__(self, path: AnyPath, mode: Text = ..., overwrite: bool = ...) -> None: ...
|
||||
def __init__(self, path: StrOrBytesPath, mode: Text = ..., overwrite: bool = ...) -> None: ...
|
||||
def open(self) -> ContextManager[IO[Any]]: ...
|
||||
def _open(self, get_fileobject: Callable[..., IO[AnyStr]]) -> ContextManager[IO[AnyStr]]: ...
|
||||
def get_fileobject(self, dir: Optional[AnyPath] = ..., **kwargs: Any) -> IO[Any]: ...
|
||||
def get_fileobject(self, dir: Optional[StrOrBytesPath] = ..., **kwargs: Any) -> IO[Any]: ...
|
||||
def sync(self, f: IO[Any]) -> None: ...
|
||||
def commit(self, f: IO[Any]) -> None: ...
|
||||
def rollback(self, f: IO[Any]) -> None: ...
|
||||
|
||||
def atomic_write(path: AnyPath, writer_cls: Type[AtomicWriter] = ..., **cls_kwargs: object) -> ContextManager[IO[Any]]: ...
|
||||
def atomic_write(path: StrOrBytesPath, writer_cls: Type[AtomicWriter] = ..., **cls_kwargs: object) -> ContextManager[IO[Any]]: ...
|
||||
|
||||
Reference in New Issue
Block a user