⚠️ Important:
The majority of the code in this repository is generated using AI coding tools such as GitHub Copilot (GPT-4o) and TRAE (Doubao 1.5 Pro).
UCUU is a Python utility library for function wrapping and proxying. It supports adding proxy logic to functions via decorators or patching, making it easy to extend, debug, and test.
You can install UCUU from PyPI:
pip install ucuu
Or, clone this repository and install locally:
git clone https://github.com/wZuck/ucuu.git
cd ucuu
pip install .
Example: Use a decorator to add a proxy function.
Effect: Whenmy_func
is called, it prints "My function logic" and then the proxy prints "Hello, hello ucuu".
from ucuu.decorator import ucuu
@ucuu("package_utils.print_ucuu_hello", ending_words="hello ucuu")
def my_func():
print("My function logic")
Example: Patch an existing function with a proxy.
Effect: Whensome_func
is called, it prints "Original logic" and then the proxy prints "Hello, patch mode".
from ucuu.decorator import ucuu
def some_func():
print("Original logic")
some_func = ucuu("package_utils.print_ucuu_hello", ending_words="patch mode")(some_func)
Example: Implement a proxy function to be called by the decorator or patch.
Effect: Prints different messages depending on theending_words
argument.
# tests/package_utils/test_print.py
def print_ucuu_hello(ending_words=None, *args, **kwargs):
if ending_words is None:
print("No Ending Words.")
elif ending_words == "please raise errors":
raise NotImplementedError('Raise Error due to requests')
else:
print(f"Hello, {ending_words}")
- See the
tests/
directory for test cases covering decorator usage, patching, exception handling, argument binding, and more.
Contributions via PR or issues are welcome!
For suggestions or questions, please leave a message at GitHub Issues.