improve typing in inspect (#6020)

This commit is contained in:
Anton Grübel
2021-09-19 12:11:55 +09:00
committed by GitHub
parent 0506182348
commit caa642dd3b
2 changed files with 19 additions and 8 deletions

View File

@@ -117,10 +117,14 @@ 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?
@@ -128,7 +132,9 @@ class Signature:
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(
@@ -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
@@ -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:

View File

@@ -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