mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-28 22:56:55 +08:00
Replace a few instances of IO with protocols (#4296)
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
||||
import sys
|
||||
import types
|
||||
from _typeshed import StrPath
|
||||
from typing import IO, Any, List, Optional, Tuple, TypeVar, Union
|
||||
from typing import IO, Any, List, Optional, Protocol, Tuple, TypeVar, Union
|
||||
|
||||
from _imp import (
|
||||
acquire_lock as acquire_lock,
|
||||
@@ -40,12 +40,23 @@ class NullImporter:
|
||||
def __init__(self, path: StrPath) -> None: ...
|
||||
def find_module(self, fullname: Any) -> None: ...
|
||||
|
||||
# PathLike doesn't work for the pathname argument here
|
||||
def load_source(name: str, pathname: str, file: Optional[IO[Any]] = ...) -> types.ModuleType: ...
|
||||
def load_compiled(name: str, pathname: str, file: Optional[IO[Any]] = ...) -> types.ModuleType: ...
|
||||
def load_package(name: str, path: StrPath) -> types.ModuleType: ...
|
||||
def load_module(name: str, file: IO[Any], filename: str, details: Tuple[str, str, int]) -> types.ModuleType: ...
|
||||
# Technically, a text file has to support a slightly different set of operations than a binary file,
|
||||
# but we ignore that here.
|
||||
class _FileLike(Protocol):
|
||||
closed: bool
|
||||
mode: str
|
||||
def read(self) -> Union[str, bytes]: ...
|
||||
def close(self) -> Any: ...
|
||||
def __enter__(self) -> Any: ...
|
||||
def __exit__(self, *args: Any) -> Any: ...
|
||||
|
||||
# PathLike doesn't work for the pathname argument here
|
||||
def load_source(name: str, pathname: str, file: Optional[_FileLike] = ...) -> types.ModuleType: ...
|
||||
def load_compiled(name: str, pathname: str, file: Optional[_FileLike] = ...) -> types.ModuleType: ...
|
||||
def load_package(name: str, path: StrPath) -> types.ModuleType: ...
|
||||
def load_module(name: str, file: Optional[_FileLike], filename: str, details: Tuple[str, str, int]) -> types.ModuleType: ...
|
||||
|
||||
# IO[Any] is a TextIOWrapper if name is a .py file, and a FileIO otherwise.
|
||||
if sys.version_info >= (3, 6):
|
||||
def find_module(
|
||||
name: str, path: Union[None, List[str], List[os.PathLike[str]], List[StrPath]] = ...
|
||||
@@ -56,4 +67,4 @@ else:
|
||||
|
||||
def reload(module: types.ModuleType) -> types.ModuleType: ...
|
||||
def init_builtin(name: str) -> Optional[types.ModuleType]: ...
|
||||
def load_dynamic(name: str, path: str, file: Optional[IO[Any]] = ...) -> types.ModuleType: ...
|
||||
def load_dynamic(name: str, path: str, file: Any = ...) -> types.ModuleType: ... # file argument is ignored
|
||||
|
||||
Reference in New Issue
Block a user