8000 Use Callable[..., Any] instead of Callable[..., object] in unittest by ShaneHarvey · Pull Request #8399 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Use Callable[..., Any] instead of Callable[..., object] in unittest #8399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Use Callable[..., Any] instead of Callable[..., object]"
This reverts commit ebedc98.
  • Loading branch information
ShaneHarvey committed Jul 25, 2022
commit 9145d12e42072308743a6abd45e12b5816aa6165
2 changes: 1 addition & 1 deletion stdlib/_compression.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DecompressReader(RawIOBase):
def __init__(
self,
fp: _Reader,
decomp_factory: Callable[..., Any],
decomp_factory: Callable[..., object],
trailing_error: type[Exception] | tuple[type[Exception], ...] = ...,
**decomp_args: Any,
) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/_dummy_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ __all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "i
TIMEOUT_MAX: int
error = RuntimeError

def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
def exit() -> NoReturn: ...
def get_ident() -> int: ...
def allocate_lock() -> LockType: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Thread:
def __init__(
self,
group: None = ...,
target: Callable[..., Any] | None = ...,
target: Callable[..., object] | None = ...,
name: str | None = ...,
args: Iterable[Any] = ...,
kwargs: Mapping[str, Any] | None = ...,
Expand Down Expand Up @@ -151,7 +151,7 @@ class Timer(Thread):
def __init__(
self,
interval: float,
function: Callable[..., Any],
function: Callable[..., object],
args: Iterable[Any] | None = ...,
kwargs: Mapping[str, Any] | None = ...,
) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LockType:
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> None: ...

def start_new_thread(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> int: ...
def interrupt_main() -> None: ...
def exit() -> NoReturn: ...
def allocate_lock() -> LockType: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa:
StrOrLiteralStr = TypeVar("StrOrLiteralStr", LiteralString, str) # noqa: Y001

# Objects suitable to be passed to sys.setprofile, threading.setprofile, and similar
ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], Any]
ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object]

# Objects suitable to be passed to sys.settrace, threading.settrace, and similar
# TODO: Ideally this would be a recursive type alias
Expand Down
2 changes: 1 addition & 1 deletion stdlib/_typeshed/wsgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else:
class StartResponse(Protocol):
def __call__(
self, __status: str, __headers: list[tuple[str, str]], __exc_info: OptExcInfo | None = ...
) -> Callable[[bytes], Any]: ...
) -> Callable[[bytes], object]: ...

WSGIEnvironment: TypeAlias = dict[str, Any] # stable
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable
Expand Down
10 changes: 5 additions & 5 deletions stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else:
_T = TypeVar("_T")
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
_Context: TypeAlias = dict[str, Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
_SSLContext: TypeAlias = bool | None | ssl.SSLContext

Expand Down Expand Up @@ -74,11 +74,11 @@ class BaseEventLoop(AbstractEventLoop):
def close(self) -> None: ...
async def shutdown_asyncgens(self) -> None: ...
# Methods scheduling callbacks. All these return Handles.
def call_soon(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
def call_later(
self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
) -> TimerHandle: ...
def call_at(self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> TimerHandle: ...
def call_at(self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> TimerHandle: ...
def time(self) -> float: ...
# Future methods
def create_future(self) -> Future[Any]: ...
Expand All @@ -95,7 +95,7 @@ class BaseEventLoop(AbstractEventLoop):
def set_task_factory(self, factory: _TaskFactory | None) -> None: ...
def get_task_factory(self) -> _TaskFactory | None: ...
# Methods for interacting with threads
def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
def set_default_executor(self, executor: Any) -> None: ...
# Network I/O methods returning Futures.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/asyncio/base_subprocess.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
def terminate(self) -> None: ...
def kill(self) -> None: ...
async def _connect_pipes(self, waiter: futures.Future[Any] | None) -> None: ... # undocumented
def _call(self, cb: Callable[..., Any], *data: Any) -> None: ... # undocumented
def _call(self, cb: Callable[..., object], *data: Any) -> None: ... # undocumented
def _pipe_connection_lost(self, fd: int, exc: BaseException | None) -> None: ... # undocumented
def _pipe_data_received(self, fd: int, data: bytes) -> None: ... # undocumented
def _process_exited(self, returncode: int) -> None: ... # undocumented
Expand Down
2 changes: 1 addition & 1 deletion stdlib/asyncio/coroutines.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool:
@overload
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
@overload
def iscoroutinefunction(func: Callable[_P, Any]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
@overload
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...

Expand Down
24 changes: 12 additions & 12 deletions stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ else:
_T = TypeVar("_T")
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
_Context: TypeAlias = dict[str, Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
_SSLContext: TypeAlias = bool | None | ssl.SSLContext

Expand All @@ -70,7 +70,7 @@ class Handle:
_cancelled: bool
_args: Sequence[Any]
def __init__(
self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ...
self, callback: Callable[..., object], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ...
) -> None: ...
def cancel(self) -> None: ...
def _run(self) -> None: ...
Expand All @@ -80,7 +80,7 @@ class TimerHandle(Handle):
def __init__(
self,
when: float,
callback: Callable[..., Any],
callback: Callable[..., object],
args: Sequence[Any],
loop: AbstractEventLoop,
context: Context | None = ...,
Expand Down Expand Up @@ -133,22 +133,22 @@ class AbstractEventLoop:
# Methods scheduling callbacks. All these return Handles.
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
@abstractmethod
def call_soon(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
@abstractmethod
def call_later(
self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
) -> TimerHandle: ...
@abstractmethod
def call_at(
self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
) -> TimerHandle: ...
else:
@abstractmethod
def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
def call_soon(self, callback: Callable[..., object], *args: Any) -> Handle: ...
@abstractmethod
def call_later(self, delay: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
def call_later(self, delay: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...
@abstractmethod
def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
def call_at(self, when: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...

@abstractmethod
def time(self) -> float: ...
Expand Down Expand Up @@ -181,10 +181,10 @@ class AbstractEventLoop:
# Methods for interacting with threads
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
@abstractmethod
def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
else:
@abstractmethod
def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any) -> Handle: ...

@abstractmethod
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
Expand Down Expand Up @@ -577,7 +577,7 @@ class AbstractEventLoop:
async def sock_sendto(self, sock: socket, data: bytes, address: _Address) -> None: ...
# Signal handling.
@abstractmethod
def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_signal_handler(self, sig: int, callback: Callable[..., object], *args: Any) -> None: ...
@abstractmethod
def remove_signal_handler(self, sig: int) -> bool: ...
# Error handlers.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/futures.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Future(Awaitable[_T], Iterable[_T]):
def get_loop(self) -> AbstractEventLoop: ...
@property
def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ...
def add_done_callback(self: Self, __fn: Callable[[Self], Any], *, context: Context | None = ...) -> None: ...
def add_done_callback(self: Self, __fn: Callable[[Self], object], *, context: Context | None = ...) -> None: ...
if sys.version_info >= (3, 9):
def cancel(self, msg: Any | None = ...) -> bool: ...
else:
Expand All @@ -54,7 +54,7 @@ class Future(Awaitable[_T], Iterable[_T]):
def done(self) -> bool: ...
def result(self) -> _T: ...
def exception(self) -> BaseException | None: ...
def remove_done_callback(self: Self, __fn: Callable[[Self], Any]) -> int: ...
def remove_done_callback(self: Self, __fn: Callable[[Self], object]) -> int: ...
def set_result(self, __result: _T) -> None: ...
def set_exception(self, __exception: type | BaseException) -> None: ...
def __iter__(self) -> Generator[Any, None, _T]: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/sslproto.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ if sys.version_info < (3, 11):
def need_ssldata(self) -> bool: ...
@property
def wrapped(self) -> bool: ...
def do_handshake(self, callback: Callable[[BaseException | None], Any] | None = ...) -> list[bytes]: ...
def shutdown(self, callback: Callable[[], Any] | None = ...) -> list[bytes]: ...
def do_handshake(self, callback: Callable[[BaseException | None], object] | None = ...) -> list[bytes]: ...
def shutdown(self, callback: Callable[[], object] | None = ...) -> list[bytes]: ...
def feed_eof(self) -> None: ...
def feed_ssldata(self, data: bytes, only_handshake: bool = ...) -> tuple[list[bytes], list[bytes]]: ...
def feed_appdata(self, data: bytes, offset: int = ...) -> tuple[list[bytes], int]: ...
Expand Down
12 changes: 6 additions & 6 deletions stdlib/asyncio/unix_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from .selector_events import BaseSelectorEventLoop
# So, it is special cased.
class AbstractChildWatcher:
@abstractmethod
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
@abstractmethod
def remove_child_handler(self, pid: int) -> bool: ...
@abstractmethod
Expand Down Expand Up @@ -67,13 +67,13 @@ if sys.platform != "win32":
class SafeChildWatcher(BaseChildWatcher):
def __enter__(self: Self) -> Self: ...
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...

class FastChildWatcher(BaseChildWatcher):
def __enter__(self: Self) -> Self: ...
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...

class _UnixSelectorEventLoop(BaseSelectorEventLoop): ...
Expand Down Expand Up @@ -102,7 +102,7 @@ if sys.platform != "win32":
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...

Expand All @@ -115,7 +115,7 @@ if sys.platform != "win32":
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
) -> None: ...
def __del__(self, _warn: _Warn = ...) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...

Expand All @@ -129,5 +129,5 @@ if sys.platform != "win32":
def is_active(self) -> bool: ...
def close(self) -> None: ...
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...
2 changes: 1 addition & 1 deletion stdlib/asyncio/windows_utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if sys.platform == "win32":
@property
def handle(self) -> int: ...
def fileno(self) -> int: ...
def close(self, *, CloseHandle: Callable[[int], Any] = ...) -> None: ...
def close(self, *, CloseHandle: Callable[[int], object] = ...) -> None: ...

class Popen(subprocess.Popen[AnyStr]):
stdin: PipeHandle | None # type: ignore[assignment]
Expand Down
2 changes: 1 addition & 1 deletion stdlib/atexit.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def _clear() -> None: ...
def _ncallbacks() -> int: ...
def _run_exitfuncs() -> None: ...
def register(func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Callable[_P, _T]: ...
def unregister(func: Callable[..., Any]) -> None: ...
def unregister(func: Callable[..., object]) -> None: ...
16 changes: 8 additions & 8 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class type:
def __instancecheck__(self, __instance: Any) -> bool: ...
def __subclasscheck__(self, __subclass: type) -> bool: ...
@classmethod
def __prepare__(metacls, __name: str, __bases: tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ...
def __prepare__(metacls, __name: str, __bases: tuple[type, ...], **kwds: Any) -> Mapping[str, object]: ...
if sys.version_info >= (3, 10):
def __or__(self, __t: Any) -> types.UnionType: ...
def __ror__(self, __t: Any) -> types.UnionType: ...
Expand Down Expand Up @@ -1189,7 +1189,7 @@ def any(__iterable: Iterable[object]) -> bool: ...
def ascii(__obj: object) -> str: ...
def bin(__number: int | SupportsIndex) -> str: ...
def breakpoint(*args: Any, **kws: Any) -> None: ...
def callable(__obj: object) -> TypeGuard[Callable[..., Any]]: ...
def callable(__obj: object) -> TypeGuard[Callable[..., object]]: ...
def chr(__i: int) -> str: ...

# We define this here instead of using os.PathLike to avoid import cycle issues.
Expand Down Expand Up @@ -1243,18 +1243,18 @@ def divmod(__x: SupportsDivMod[_T_contra, _T_co], __y: _T_contra) -> _T_co: ...
@overload
def divmod(__x: _T_contra, __y: SupportsRDivMod[_T_contra, _T_co]) -> _T_co: ...

# The `globals` argument to `eval` has to be `dict[str, Any]` rather than `dict[str, Any]` due to invariance.
# The `globals` argument to `eval` has to be `dict[str, Any]` rather than `dict[str, object]` due to invariance.
# (The `globals` argument has to be a "real dict", rather than any old mapping, unlike the `locals` argument.)
def eval(
__source: str | ReadableBuffer | CodeType, __globals: dict[str, Any] | None = ..., __locals: Mapping[str, Any] | None = ...
__source: str | ReadableBuffer | CodeType, __globals: dict[str, Any] | None = ..., __locals: Mapping[str, object] | None = ...
) -> Any: ...

# Comment above regarding `eval` applies to `exec` as well
if sys.version_info >= (3, 11):
def exec(
__source: str | ReadableBuffer | CodeType,
__globals: dict[str, Any] | None = ...,
__locals: Mapping[str, Any] | None = ...,
__locals: Mapping[str, object] | None = ...,
*,
closure: tuple[_Cell, ...] | None = ...,
) -> None: ...
Expand All @@ -1263,7 +1263,7 @@ else:
def exec(
__source: str | ReadableBuffer | CodeType,
__globals: dict[str, Any] | None = ...,
__locals: Mapping[str, Any] | None = ...,
__locals: Mapping[str, object] | None = ...,
) -> None: ...

def exit(code: object = ...) -> NoReturn: ...
Expand Down Expand Up @@ -1750,8 +1750,8 @@ class zip(Iterator[_T_co], Generic[_T_co]):
# Return type of `__import__` should be kept the same as return type of `importlib.import_module`
def __import__(
name: str,
globals: Mapping[str, Any] | None = ...,
locals: Mapping[str, Any] | None = ...,
globals: Mapping[str, object] | None = ...,
locals: Mapping[str, object] | None = ...,
fromlist: Sequence[str] = ...,
level: int = ...,
) -> types.ModuleType: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/concurrent/futures/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Future(Generic[_T]):
def cancelled(self) -> bool: ...
def running(self) -> bool: ...
def done(self) -> bool: ...
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
def add_done_callback(self, fn: Callable[[Future[_T]], object]) -> None: ...
def result(self, timeout: float | None = ...) -> _T: ...
def set_running_or_notify_cancel(self) -> bool: ...
def set_result(self, result: _T) -> None: ...
Expand Down
Loading
0