Analyze Module¶
Module: piethorn.typing.analyze
Overview¶
This module wraps inspect with stable helper objects for examining callables
and other Python objects.
Argument¶
- class Argument(parameter)¶
Wrapper around
inspect.Parameterwith stable properties:parameternamekinddefaultannotation
Arguments¶
- class Arguments(iterable=None)¶
Sequence wrapper over analyzed parameters.
Important properties:
positionalkeywordpositional_or_keywordhas_argshas_kwargsarg_count
Info¶
- class Info(obj)¶
Inspection wrapper for an arbitrary Python object.
Important properties:
objectargumentsreturn_annotation
Inspection predicates¶
callable(),awaitable(),ismethod(),ismethoddescriptor(),ismethodwrapper(),isfunction(),isgeneratorfunction(),isgenerator(),isasyncgenfunction(),isasyncgen(),isclass(),ismodule(),ismemberdescriptor(),isgetsetdescriptor(),isdatadescriptor(),iscoroutinefunction(),iscoroutine(),isroutine(),istraceback(),isframe(),iscode(),isbuiltin(),isabstract()
analyze¶
- analyze(obj)¶
Convenience entry point returning
Info.Example¶
from piethorn.typing.analyze import analyze def sample(a, /, b: int, *args, c=3, **kwargs) -> str: return "ok" info = analyze(sample) info.arguments.positional # ("a",) info.arguments.positional_or_keyword # ("b",) info.arguments.keyword # ("c",)
Autodoc¶
- class piethorn.typing.analyze.Argument(parameter: Parameter)¶
Wrap
inspect.Parameterwith stable comparison-friendly accessors.- property annotation¶
Return the parameter annotation.
- property default¶
Return the parameter default value.
- property kind¶
Return the parameter kind.
- property name¶
Return the parameter name.
- property parameter¶
Return the wrapped
inspect.Parameter.
- class piethorn.typing.analyze.Arguments(iterable: Iterable[Argument | Parameter] = None)¶
Provide a sequence view over analyzed callable parameters.
- property arg_count¶
Return the number of non-variadic positional parameters.
- property has_args¶
Return whether
*argsis present.
- property has_kwargs¶
Return whether
**kwargsis present.
- property keyword¶
Return names of keyword-only parameters.
- property positional¶
Return names of positional-only parameters.
- property positional_or_keyword¶
Return names of parameters that accept positional or keyword binding.
- class piethorn.typing.analyze.Info(obj)¶
Collect inspection metadata and predicates for an arbitrary object.
- property arguments¶
Return analyzed callable arguments when the object is callable.
- awaitable()¶
Return whether the inspected object is awaitable.
- callable()¶
Return whether the inspected object is callable.
- isabstract()¶
Return whether the inspected object is abstract.
- isasyncgen()¶
Return whether the inspected object is an async generator iterator.
- isasyncgenfunction()¶
Return whether the inspected object is an async generator function.
- isbuiltin()¶
Return whether the inspected object is a built-in function or method.
- isclass()¶
Return whether the inspected object is a class.
- iscode()¶
Return whether the inspected object is a code object.
- iscoroutine()¶
Return whether the inspected object is a coroutine object.
- iscoroutinefunction()¶
Return whether the inspected object is a coroutine function.
- isdatadescriptor()¶
Return whether the inspected object is a data descriptor.
- isframe()¶
Return whether the inspected object is a frame.
- isfunction()¶
Return whether the inspected object is a Python function.
- isgenerator()¶
Return whether the inspected object is a generator iterator.
- isgeneratorfunction()¶
Return whether the inspected object is a generator function.
- isgetsetdescriptor()¶
Return whether the inspected object is a get-set descriptor.
- ismemberdescriptor()¶
Return whether the inspected object is a member descriptor.
- ismethod()¶
Return whether the inspected object is a bound method.
- ismethoddescriptor()¶
Return whether the inspected object is a method descriptor.
- ismethodwrapper()¶
Return whether the inspected object is a method-wrapper instance.
- ismodule()¶
Return whether the inspected object is a module.
- isroutine()¶
Return whether the inspected object is any routine-like callable.
- istraceback()¶
Return whether the inspected object is a traceback.
- property object¶
Return the inspected object.
- property return_annotation¶
Return the callable’s declared return annotation when available.
- piethorn.typing.analyze.analyze(obj)¶
This function will analyze the provided object.
- Parameters:
obj – The object to analyze.
- Returns:
The information on the object.