Backport many ParamSpec-related changes to Python 2 (#7054)

This commit is contained in:
Alex Waygood
2022-01-27 15:57:26 +00:00
committed by GitHub
parent 5b39d07cd9
commit 2d8decd237
7 changed files with 21 additions and 8 deletions

View File

@@ -1,7 +1,9 @@
from types import CodeType, FrameType, TracebackType
from typing import IO, Any, Callable, Iterable, Mapping, SupportsInt, TypeVar
from typing_extensions import ParamSpec
_T = TypeVar("_T")
_P = ParamSpec("_P")
_TraceDispatch = Callable[[FrameType, str, Any], Any] # TODO: Recursive type
_ExcInfo = tuple[type[BaseException], BaseException, FrameType]
@@ -61,7 +63,7 @@ class Bdb:
def run(self, cmd: str | CodeType, globals: dict[str, Any] | None = ..., locals: Mapping[str, Any] | None = ...) -> None: ...
def runeval(self, expr: str, globals: dict[str, Any] | None = ..., locals: Mapping[str, Any] | None = ...) -> None: ...
def runctx(self, cmd: str | CodeType, globals: dict[str, Any] | None, locals: Mapping[str, Any] | None) -> None: ...
def runcall(self, __func: Callable[..., _T], *args: Any, **kwds: Any) -> _T | None: ...
def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> _T | None: ...
class Breakpoint:

View File

@@ -1,6 +1,7 @@
from _typeshed import Self
from types import CodeType
from typing import Any, Callable, Text, TypeVar
from typing_extensions import ParamSpec
def run(statement: str, filename: str | None = ..., sort: str | int = ...) -> None: ...
def runctx(
@@ -8,6 +9,7 @@ def runctx(
) -> None: ...
_T = TypeVar("_T")
_P = ParamSpec("_P")
_Label = tuple[str, int, str]
class Profile:
@@ -23,6 +25,6 @@ class Profile:
def snapshot_stats(self) -> None: ...
def run(self: Self, cmd: str) -> Self: ...
def runctx(self: Self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ...
def runcall(self, __func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ...
def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ...
def label(code: str | CodeType) -> _Label: ... # undocumented

View File

@@ -1,16 +1,18 @@
from types import TracebackType
from typing import IO, Any, Callable, ContextManager, Iterable, Iterator, Optional, Protocol, TypeVar
from typing_extensions import ParamSpec
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_F = TypeVar("_F", bound=Callable[..., Any])
_P = ParamSpec("_P")
_ExitFunc = Callable[[Optional[type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
class GeneratorContextManager(ContextManager[_T_co]):
def __call__(self, func: _F) -> _F: ...
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, ContextManager[_T]]: ...
def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ...
class _SupportsClose(Protocol):

View File

@@ -2,8 +2,10 @@ from bdb import Bdb
from cmd import Cmd
from types import FrameType, TracebackType
from typing import IO, Any, Callable, ClassVar, Iterable, Mapping, TypeVar
from typing_extensions import ParamSpec
_T = TypeVar("_T")
_P = ParamSpec("_P")
line_prefix: str # undocumented
@@ -12,7 +14,7 @@ class Restart(Exception): ...
def run(statement: str, globals: dict[str, Any] | None = ..., locals: Mapping[str, Any] | None = ...) -> None: ...
def runeval(expression: str, globals: dict[str, Any] | None = ..., locals: Mapping[str, Any] | None = ...) -> Any: ...
def runctx(statement: str, globals: dict[str, Any], locals: Mapping[str, Any]) -> None: ...
def runcall(func: Callable[..., _T], *args: Any, **kwds: Any) -> _T | None: ...
def runcall(func: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> _T | None: ...
def set_trace() -> None: ...
def post_mortem(t: TracebackType | None = ...) -> None: ...
def pm() -> None: ...

View File

@@ -1,5 +1,6 @@
from _typeshed import Self
from typing import Any, Callable, Text, TypeVar
from typing_extensions import ParamSpec
def run(statement: str, filename: str | None = ..., sort: str | int = ...) -> None: ...
def runctx(
@@ -7,6 +8,7 @@ def runctx(
) -> None: ...
_T = TypeVar("_T")
_P = ParamSpec("_P")
_Label = tuple[str, int, str]
class Profile:
@@ -22,5 +24,5 @@ class Profile:
def snapshot_stats(self) -> None: ...
def run(self: Self, cmd: str) -> Self: ...
def runctx(self: Self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ...
def runcall(self, __func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ...
def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ...
def calibrate(self, m: int, verbose: int = ...) -> float: ...

View File

@@ -1,8 +1,10 @@
import types
from _typeshed import StrPath
from typing import Any, Callable, Mapping, Optional, Sequence, TypeVar
from typing_extensions import ParamSpec
_T = TypeVar("_T")
_P = ParamSpec("_P")
_localtrace = Callable[[types.FrameType, str, Any], Callable[..., Any]]
_fileModuleFunction = tuple[str, Optional[str], str]
@@ -38,7 +40,7 @@ class Trace:
def runctx(
self, cmd: str | types.CodeType, globals: Mapping[str, Any] | None = ..., locals: Mapping[str, Any] | None = ...
) -> None: ...
def runfunc(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ...
def runfunc(self, func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ...
def file_module_function_of(self, frame: types.FrameType) -> _fileModuleFunction: ...
def globaltrace_trackcallers(self, frame: types.FrameType, why: str, arg: Any) -> None: ...
def globaltrace_countfuncs(self, frame: types.FrameType, why: str, arg: Any) -> None: ...

View File

@@ -4,6 +4,7 @@ from abc import abstractmethod
from logging import Logger
from types import TracebackType
from typing import Any, Callable, Container, Generic, Iterable, Iterator, Optional, Protocol, TypeVar
from typing_extensions import ParamSpec
FIRST_COMPLETED: str
FIRST_EXCEPTION: str
@@ -20,8 +21,8 @@ class CancelledError(Error): ...
class TimeoutError(Error): ...
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_P = ParamSpec("_P")
# Copied over Collection implementation as it does not exist in Python 2 and <3.6.
# Also to solve pytype issues with _Collection.
@@ -46,7 +47,7 @@ class Future(Generic[_T]):
def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ...
class Executor:
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
def submit(self, fn: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...) -> Iterator[_T]: ...
def shutdown(self, wait: bool = ...) -> None: ...
def __enter__(self: Self) -> Self: ...