Class
Class ¶
Class(cls, init=True, public=True, inherited=True, static_methods=True, protected=False, private=False, classmethod=True, skip_self=True)
Wraps a class or class instance and provides information about its methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type or object
|
The class or class instance to wrap. |
required |
init
|
bool
|
Include the class's init method. |
True
|
public
|
bool
|
Include public methods. |
True
|
inherited
|
bool
|
Include inherited methods. |
True
|
static_methods
|
bool
|
Include static methods. |
True
|
protected
|
bool
|
Include protected methods. |
False
|
private
|
bool
|
Include private methods. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
cls |
type or object
|
The class or class instance that was passed as an argument. |
is_initialized |
bool
|
Whether the class has been initialized as an instance. |
name |
str
|
The name of the class. |
instance |
object | None
|
The instance of the class if it has been initialized, otherwise None. |
docstring |
str | None
|
The docstring of the class if it exists, otherwise None. |
has_docstring |
bool
|
Whether the class has a docstring. |
extractor_kwargs |
dict
|
The keyword arguments used to initialize the MethodExtractor object. |
has_init |
bool
|
Whether the class has an init method. |
description |
str
|
The description of the class from its docstring. |
Source code in objinspect/_class.py
methods
property
¶
Returns the list of methods of the class or instance as a list of :class:Function objects.
init ¶
Initializes the class as an instance using the provided arguments.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the class is already initialized. |
Source code in objinspect/_class.py
call_method ¶
Calls the specified method on the class or instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str | int
|
The name or index of the method to call. |
required |
*args
|
Positional arguments to pass to the method. |
()
|
|
**kwargs
|
Keyword arguments to pass to the method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of calling the specified method. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the class has not been initialized. |
Source code in objinspect/_class.py
get_method ¶
Retrieves a method from the list of methods of the class or instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str | int
|
The method name or index to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Method |
Method
|
The |
Source code in objinspect/_class.py
split_init_args ¶
Split the arguments into those that should be passed to the init method and those that should be passed to the method call.