Method Definitions
Method registration and decorator functionality for Quick Metric.
Provides the core decorator for registering custom metric methods with a thread-safe registry system.
Classes:
| Name | Description |
|---|---|
MetricRegistry : Thread-safe registry for user-defined metric methods |
|
Functions:
| Name | Description |
|---|---|
metric_method : Decorator for registering custom metric functions |
|
get_method : Retrieve a registered method by name |
|
get_registered_methods : Get dictionary of all registered methods |
|
list_method_names : List all registered method names |
|
clear_methods : Clear all methods from the registry |
|
Constants
METRICS_METHODS : Global registry instance
MetricRegistry
Thread-safe registry for user-defined metric methods.
Provides a centralized, thread-safe way to register and access metric methods decorated with @metric_method.
Source code in quick_metric/_method_definitions.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
register(func)
Register a user function as a metric method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
User function to register. Must accept at least one parameter. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
The original function, unchanged. |
Raises:
| Type | Description |
|---|---|
InvalidMethodSignatureError
|
If function has invalid signature. |
Source code in quick_metric/_method_definitions.py
get_method(name)
Get a registered method by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the method. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
The registered method. |
Raises:
| Type | Description |
|---|---|
MethodNotFoundError
|
If method not registered. |
Source code in quick_metric/_method_definitions.py
get_methods()
Get copy of all registered methods.
Returns:
| Type | Description |
|---|---|
Dict[str, Callable]
|
Copy of methods dictionary. |
Raises:
| Type | Description |
|---|---|
RegistryLockError
|
If threading lock fails. |
Source code in quick_metric/_method_definitions.py
list_method_names()
Get list of registered method names.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of method names. |
Raises:
| Type | Description |
|---|---|
EmptyRegistryError
|
If no methods registered. |
RegistryLockError
|
If threading lock fails. |
Source code in quick_metric/_method_definitions.py
clear()
Clear all registered methods (for testing).
Raises:
| Type | Description |
|---|---|
RegistryLockError
|
If threading lock fails. |
Source code in quick_metric/_method_definitions.py
metric_method(func_or_name=None)
Decorator to register a user function as a metric method, or query registered methods.
Can be used in three ways: 1. As a decorator: @metric_method 2. To get all methods: metric_method() 3. To get a specific method: metric_method('method_name')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func_or_name
|
Callable or str
|
User function to register when used as decorator, or method name to retrieve. |
None
|
Returns:
| Type | Description |
|---|---|
Callable or dict
|
When used as decorator: returns the original function unchanged. When called without args: returns dict of all registered methods. When called with method name: returns the specific method. |
Examples:
As a decorator:
To get all methods:
To get a specific method: