Skip to content

Improve inspect stubs #7050

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 3 commits into from
Jan 27, 2022
Merged
Changes from all commits
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
18 changes: 9 additions & 9 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ if sys.version_info >= (3, 7):
from types import ClassMethodDescriptorType, WrapperDescriptorType, MemberDescriptorType, MethodDescriptorType

from typing import Any, ClassVar, Coroutine, NamedTuple, Protocol, TypeVar, Union
from typing_extensions import Literal, TypeGuard
from typing_extensions import Literal, ParamSpec, TypeGuard

_P = ParamSpec("_P")
_T_cont = TypeVar("_T_cont", contravariant=True)
_V_cont = TypeVar("_V_cont", contravariant=True)

#
# Types and members
Expand Down Expand Up @@ -80,9 +84,6 @@ if sys.version_info >= (3, 8):
else:
def isasyncgenfunction(object: object) -> bool: ...

_T_cont = TypeVar("_T_cont", contravariant=True)
_V_cont = TypeVar("_V_cont", contravariant=True)

class _SupportsSet(Protocol[_T_cont, _V_cont]):
def __set__(self, __instance: _T_cont, __value: _V_cont) -> None: ...

Expand Down Expand Up @@ -166,7 +167,6 @@ class Signature:
empty = _empty
@property
def parameters(self) -> types.MappingProxyType[str, Parameter]: ...
# TODO: can we be more specific here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's either the empty marker or whatever the user put in an annotation. I don't think we can express that better in the current type system.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

@property
def return_annotation(self) -> Any: ...
def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
Expand All @@ -177,17 +177,17 @@ class Signature:
if sys.version_info >= (3, 10):
@classmethod
def from_callable(
cls,
cls: type[Self],
obj: Callable[..., Any],
*,
follow_wrapped: bool = ...,
globals: Mapping[str, Any] | None = ...,
locals: Mapping[str, Any] | None = ...,
eval_str: bool = ...,
) -> Signature: ...
) -> Self: ...
else:
@classmethod
def from_callable(cls, obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ...
def from_callable(cls: type[Self], obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Self: ...

if sys.version_info >= (3, 10):
def get_annotations(
Expand Down Expand Up @@ -318,7 +318,7 @@ def formatargvalues(
formatvalue: Callable[[Any], str] | None = ...,
) -> str: ...
def getmro(cls: type) -> tuple[type, ...]: ...
def getcallargs(__func: Callable[..., Any], *args: Any, **kwds: Any) -> dict[str, Any]: ...
def getcallargs(__func: Callable[_P, Any], *args: _P.args, **kwds: _P.kwargs) -> dict[str, Any]: ...

class ClosureVars(NamedTuple):
nonlocals: Mapping[str, Any]
Expand Down