pyecs.helpers.Unsafe#
Functions
|
Class decorator that automatically generates unsafe versions for all methods that return StatusCodes.FAILURE. |
|
Decorator that automatically generates an unsafe version of a method. |
Process all methods decorated with @generate_unsafe and add their unsafe versions to the class. |
- pyecs.helpers.Unsafe.generate_unsafe(exception_type=<class 'pyecs.exceptions.Exceptions.OperationFailedError'>, error_message=None)[source]#
Decorator that automatically generates an unsafe version of a method.
The unsafe version raises an exception instead of returning StatusCodes.FAILURE. The decorated function gets a new unsafe attribute that is the exception-raising version.
- Return type:
Callable
[[Callable
[[ParamSpec
(P
)],TypeVar
(R
)]],Callable
[[ParamSpec
(P
)],TypeVar
(R
)]]- Parameters:
- Usage:
@generate_unsafe(ComponentNotFoundError, “Component not found on entity”) def get_component(self, entity: Entity, component_type: type[Component]) -> Component | Literal[StatusCodes.FAILURE]:
…
# This automatically generates: # Safe version: component = world.get_component(entity, Position) # Returns FAILURE on error # Strict version: component = world.get_component_or_raise(entity, Position) # Raises exception on error
- pyecs.helpers.Unsafe.process_unsafe_methods(cls)[source]#
Process all methods decorated with @generate_unsafe and add their unsafe versions to the class.