Python Inspect
inspect is a module for object inspection.
Contents
-
Python Inspect
-
Usage
- CleanDoc
- FormatArgValues
- GetArgValues
- GetAttr_Static
- GetCallArgs
- GetClassTree
- GetClosureVars
- GetComments
- GetCoroutineLocals
- GetCoroutineState
- GetCurrentFrame
- GetDoc
- GetFile
- GetFrameInfo
- GetFullArgSpec
- GetGeneratorLocals
- GetGeneratorState
- GetInnerFrames
- GetMembers
- GetMembers_Static
- GetModule
- GetModuleName
- GetMro
- GetOuterFrames
- GetSource
- GetSourceFile
- GetSourceLines
- Get_Annotations
- IsAbstract
- IsAwaitable
- IsAsyncGen
- IsAsyncGenFunction
- IsBuiltin
- IsClass
- IsCode
- IsCoroutine
- IsCoroutineFunction
- IsDataDescriptor
- IsFrame
- IsFunction
- IsGenerator
- IsGeneratorFunction
- IsGetSetDescriptor
- IsMemberDescriptor
- IsMethod
- IsMethodDescriptor
- IsMethodWrapper
- IsModule
- IsRoutine
- IsTraceback
- Signature
- Stack
- Trace
- Unwrap
- See also
-
Usage
Usage
CleanDoc
FormatArgValues
GetArgValues
GetAttr_Static
GetCallArgs
GetClassTree
GetClosureVars
GetComments
GetCoroutineLocals
GetCoroutineState
GetCurrentFrame
Return the current frame object.
GetDoc
GetFile
GetFrameInfo
Return an inspect.Traceback object with the following properties.
Properties |
Value |
code_context |
List of lines of context associated with a traceback |
filename |
File name associated with a traceback |
function |
Function name associated with a traceback |
index |
Index of the current line within code_context |
lineno |
Line number associated with a traceback |
positions |
A dis.Positions object associated with a traceback |
GetFullArgSpec
GetGeneratorLocals
GetGeneratorState
GetInnerFrames
Return a list of inspect.FrameInfo objects with the following properties.
Properties |
Value |
code_context |
List of lines of context associated with a frame |
filename |
File name associated with a frame |
frame |
The frame object |
function |
Function name associated with a frame |
index |
Index of the current line within code_context |
lineno |
Line number associated with a frame |
positions |
A dis.Positions object associated with a frame |
GetMembers
GetMembers_Static
GetModule
GetModuleName
GetMro
GetOuterFrames
Return a list of inspect.FrameInfo objects
GetSource
GetSourceFile
GetSourceLines
Get_Annotations
IsAbstract
IsAwaitable
IsAsyncGen
IsAsyncGenFunction
IsBuiltin
IsClass
IsCode
IsCoroutine
IsCoroutineFunction
IsDataDescriptor
IsFrame
IsFunction
IsGenerator
IsGeneratorFunction
IsGetSetDescriptor
IsMemberDescriptor
IsMethod
IsMethodDescriptor
IsMethodWrapper
IsModule
IsRoutine
IsTraceback
Signature
Returns an inspect.Signature object with the following methods and properties.
Parameters
A mapping of inspect.Parameter objects with the following methods and properties.
Properties |
Value |
name |
String name of the parameter |
default |
Default value of the parameter, or inspect.Parameter.empty |
annotation |
Annotation for the parameter, or inspect.Parameter.empty |
kind |
Describes how values are set into a parameter |
Possible values for inspect.Parameter.kind are:
inspect.Parameter.POSITIONAL_ONLY
inspect.Parameter.POSITIONAL_OR_KEYWORD
inspect.Parameter.VAR_POSITIONAL
inspect.Parameter.KEYWORD_ONLY
inspect.Parameter.VAR_KEYWORD
To get a plain-text explanation of a inspect.Parameter.kind value, try accessing the kind.description property.
Method |
Value |
replace |
Create a new inspect.Parameter object with some modification |
Return_Annotation
The return annotation for the callable. If there is no annotation, is set to the inspect.Signature.empty sentinel.
Bind
Creates an inspect.BoundArguments object with the following methods and properties.
Properties |
Value |
arguments |
A mapping of parameter names to values |
args |
A tuple of positional arguments values |
kwargs |
A dict of keyword arguments values |
signature |
A reference to the parent inspect.Signature object |
Methods |
Meaning |
apply_defaults |
Set args to an empty tuple and kwargs to an empty dict |
Bind_Partial
Creates an inspect.BoundArguments object.
Replace
Create a new inspect.Signature object with some modification.
Stack
Return a list of inspect.FrameInfo objects.
Trace
Return a list of inspect.FrameInfo objects.
Unwrap
See also
Python inspect module documentation
Python Module of the Day article for inspect