Advanced tools for callable objects in Python.
Table of Contents
Provides advanced tools for callable objects in Python 3.x.
To get a local copy up and running follow these simple example steps.
Does not require any prerequisites.
- Clone the repo
git clone https://github.com/TahsinCr/python-callabletools.git- Install PIP packages
pip install callabletoolsLet's try to retrieve a callable object's arguments, argument count, return result, and the arguments with their given values.
from callabletoolx import (
get_arguments, get_argument_length, get_return_argument, get_argument_values
)
def item_to_string(key1:str, key2, start:str='-', *keys, sep:str=', ', **items:int) -> str:
items = [f'{k}:{v}' for k, v in items]
return start + sep.join([key1, key2, *keys, items])
func_args = ['test1', 'test2', '--', 'test3']
func_kwargs = {
'ex' : 'test4'
}
arguments = get_arguments(item_to_string)
print("FuncArgs:", *arguments, sep='\n', end='\n\n')
print("FuncArgLength: {}".format(get_argument_length(item_to_string)), end='\n\n')
print("FuncReturnArg: \n{}".format(get_return_argument(item_to_string)), end='\n\n')
print(
"FuncArgValues:",
*get_argument_values(arguments, func_args, func_kwargs),
sep='\n', end='\n\n'
)Output
FuncArgs:
Argument(name: key1, type: <class 'str'>, default: Ellipsis, argtype: ARG)
Argument(name: key2, type: typing.Any, default: Ellipsis, argtype: ARG)
Argument(name: start, type: <class 'str'>, default: Ellipsis, argtype: ARG)
Argument(name: keys, type: typing.Any, default: Ellipsis, argtype: ARGS)
Argument(name: sep, type: <class 'str'>, default: ', ', argtype: ARG)
Argument(name: items, type: <class 'int'>, default: Ellipsis, argtype: KWARGS)
FuncArgLength: 6
FuncReturnArg:
Argument(name: return, type: <class 'str'>, default: Ellipsis, argtype: RETURN)
FuncArgValues:
ArgumentValue(name: key1, type: <class 'str'>, default: Ellipsis, argtype: ARG, value: 'test1')
ArgumentValue(name: key2, type: typing.Any, default: Ellipsis, argtype: ARG, value: 'test2')
ArgumentValue(name: start, type: <class 'str'>, default: Ellipsis, argtype: ARG, value: '--')
ArgumentValue(name: keys, type: typing.Any, default: Ellipsis, argtype: ARGS, value: ['test3'])
ArgumentValue(name: sep, type: <class 'str'>, default: ', ', argtype: ARG, value: ', ')
ArgumentValue(name: items, type: <class 'int'>, default: Ellipsis, argtype: KWARGS, value: {'ex': 'test4'})
For more examples, please refer to the Documentation
- Add documentation.
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
-
Fork the Project
-
Create your Feature Branch (
git checkout -b feature/AmazingFeature) -
Commit your Changes (
git commit -m 'Add some AmazingFeature') -
Push to the Branch (
git push origin feature/AmazingFeature) -
Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Email: TahsinCr@outlook.com
X: @TahsinCrs
LinkedIn: TahsinCr
