caikit.core.toolkit.wip_decorator
Attributes
Classes
Create a collection of name/value pairs. |
|
Create a collection of name/value pairs. |
|
Temporarily disable wip decorator for a particular block of code |
Functions
Utility function to disable decorator functionality. |
|
Utility function to enable decorator functionality. |
|
|
Decorator that can be used to mark a function |
|
Utility function to cover common decorator handling |
|
Utility function to run action |
Module Contents
- caikit.core.toolkit.wip_decorator.error
- caikit.core.toolkit.wip_decorator.message_format = '{} is still in the {} phase and subject to change!'
- caikit.core.toolkit.wip_decorator._ENABLE_DECORATOR = True
- class caikit.core.toolkit.wip_decorator.WipCategory(*args, **kwds)[source]
Bases:
enum.EnumCreate a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3
Access them by:
attribute access:
>>> Color.RED <Color.RED: 1>
value lookup:
>>> Color(1) <Color.RED: 1>
name lookup:
>>> Color['RED'] <Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color) 3
>>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.
- WIP = 1
- BETA = 2
- class caikit.core.toolkit.wip_decorator.Action(*args, **kwds)[source]
Bases:
enum.EnumCreate a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3
Access them by:
attribute access:
>>> Color.RED <Color.RED: 1>
value lookup:
>>> Color(1) <Color.RED: 1>
name lookup:
>>> Color['RED'] <Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color) 3
>>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.
- ERROR = 1
- WARNING = 2
- caikit.core.toolkit.wip_decorator.disable_wip()[source]
Utility function to disable decorator functionality. Mainly designed for testing
- caikit.core.toolkit.wip_decorator.enable_wip()[source]
Utility function to enable decorator functionality. Mainly designed for testing
- class caikit.core.toolkit.wip_decorator.TempDisableWIP[source]
Temporarily disable wip decorator for a particular block of code
NOTE: There is a potential race condition possible here in cases where other code using wip decorator gets called at the same time this context based disabling functionality is invoked. If this happens, the decorator will get disabled for all the functions invoking at the same time. This is because we are using the global disable / enable functions for this class.
- caikit.core.toolkit.wip_decorator.work_in_progress(*args, **kwargs)[source]
Decorator that can be used to mark a function or a class as “work in progress”. It will result in a warning being emitted when the function / class is used.
- Args:
- category (WipCategory): Enum specifying what category of message you
want to throw
- action (Action): Enum specifying what type of action you want to take.
Example: ERROR or WARNING
Example Usage:
### Decorating class
- No configuration:
@work_in_progress class Foo:
pass
- Action and category configuration:
@work_in_progress(action=Action.WARNING, category=WipCategory.BETA) class Foo:
pass
### Decorating Function:
### Sample message:
foo is still in the BETA phase and subject to change!
- caikit.core.toolkit.wip_decorator._decorator_handler(wrapped_obj, category, action)[source]
Utility function to cover common decorator handling logic. Args:
wrapped_obj (Callable): Class or function to be decorated category (Enum(WipCategory)): Enum specifying the category of the
message
- Action (Enum(Action)): Enum specifying the action to be taken with the
decorator
- Returns:
- function:
Decorator function