Skip to content

Commit

Permalink
improve typing in inspect (#6020)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruebel authored Sep 19, 2021
1 parent 0506182 commit caa642d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 17 additions & 6 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,24 @@ if sys.version_info >= (3, 10):
else:
def signature(obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ...

class _void: ...
class _empty: ...

class Signature:
def __init__(self, parameters: Sequence[Parameter] | None = ..., *, return_annotation: Any = ...) -> None: ...
# TODO: can we be more specific here?
empty: object
def __init__(
self, parameters: Sequence[Parameter] | None = ..., *, return_annotation: Any = ..., __validate_parameters__: bool = ...
) -> None: ...
empty: _empty
@property
def parameters(self) -> types.MappingProxyType[str, Parameter]: ...
# TODO: can we be more specific here?
@property
def return_annotation(self) -> Any: ...
def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
def bind_partial(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
def replace(self: Self, *, parameters: Sequence[Parameter] | None = ..., return_annotation: Any = ...) -> Self: ...
def replace(
self: Self, *, parameters: Sequence[Parameter] | Type[_void] | None = ..., return_annotation: Any = ...
) -> Self: ...
if sys.version_info >= (3, 10):
@classmethod
def from_callable(
Expand Down Expand Up @@ -166,7 +172,7 @@ class _ParameterKind(enum.IntEnum):

class Parameter:
def __init__(self, name: str, kind: _ParameterKind, *, default: Any = ..., annotation: Any = ...) -> None: ...
empty: Any
empty: _empty
name: str
default: Any
annotation: Any
Expand All @@ -178,7 +184,12 @@ class Parameter:
KEYWORD_ONLY: ClassVar[Literal[_ParameterKind.KEYWORD_ONLY]]
VAR_KEYWORD: ClassVar[Literal[_ParameterKind.VAR_KEYWORD]]
def replace(
self: Self, *, name: str | None = ..., kind: _ParameterKind | None = ..., default: Any = ..., annotation: Any = ...
self: Self,
*,
name: str | Type[_void] = ...,
kind: _ParameterKind | Type[_void] = ...,
default: Any = ...,
annotation: Any = ...,
) -> Self: ...

class BoundArguments:
Expand Down
4 changes: 2 additions & 2 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ importlib.abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined
importlib.abc.MetaPathFinder.find_spec # Not defined on the actual class, but expected to exist.
importlib.abc.PathEntryFinder.find_spec # Not defined on the actual class, but expected to exist.
importlib.machinery.ExtensionFileLoader.get_filename # Wrapped with _check_name decorator which changes runtime signature
inspect.Parameter.empty # set as private marker _empty
inspect.Parameter.KEYWORD_ONLY
inspect.Parameter.POSITIONAL_ONLY
inspect.Parameter.POSITIONAL_OR_KEYWORD
inspect.Parameter.VAR_KEYWORD
inspect.Parameter.VAR_POSITIONAL
inspect.Parameter.replace
inspect.Signature.replace
inspect.Signature.empty # set as private marker _empty
io.BufferedRandom.truncate
io.BufferedReader.seek
io.BufferedReader.truncate
Expand Down

0 comments on commit caa642d

Please sign in to comment.