lib.py Reference¶
NewInit
¶
Source code in simple_python_template/lib.py
__call__(*constructor_args, **constructor_kwargs)
¶
Calls the wrapped constructor with the provided arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*constructor_args |
Tuple[Any, ...]
|
Positional arguments to pass to the constructor. |
()
|
**constructor_kwargs |
Dict[str, Any]
|
Keyword arguments to pass to the constructor. |
{}
|
Source code in simple_python_template/lib.py
__get__(obj, owner)
¶
Retrieves the object and owner for the descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj |
Any
|
The instance of the class. |
required |
owner |
Type[Any]
|
The owner class of the descriptor. |
required |
Returns¶
self: The NewInit instance.
Source code in simple_python_template/lib.py
__init__(constructor)
¶
Initializes the NewInit with a constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constructor |
Any
|
The constructor to wrap. |
required |
Source code in simple_python_template/lib.py
NewTypeMethod
¶
Source code in simple_python_template/lib.py
__call__(*args, **kwargs)
¶
Calls the wrapped function, handles the initialization of the wrapped class if necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args |
Tuple[Any, ...]
|
Positional arguments to pass to the wrapped function. |
()
|
**kwargs |
Dict[str, Any]
|
Keyword arguments to pass to the wrapped function. |
{}
|
Returns¶
The result of the wrapped function or an instance of the wrapped class.
Source code in simple_python_template/lib.py
__get__(inst, owner)
¶
Retrieves the instance and owner for the descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inst |
Any
|
The instance of the class. |
required |
owner |
Type[Any]
|
The owner class of the descriptor. |
required |
Returns¶
self: The NewTypeMethod instance.
Source code in simple_python_template/lib.py
__init__(func, wrapped_cls)
¶
Initializes the NewTypeMethod with a callable and the class it wraps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func |
Callable
|
The function to wrap. |
required |
wrapped_cls |
Type
|
The class that the function is associated with. |
required |
Source code in simple_python_template/lib.py
NewType(type_, **context)
¶
Creates a new type used to define new types with additional behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_ |
Type[T]
|
The base type to create a new type from. |
required |
**context |
Dict[str, Any]
|
Additional context for the new type. |
{}
|
Returns¶
tNT: A new type that behaves like the specified base type.