Skip to content

TahsinCr/python-callabletools

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn

Logo Logo


Logo

Python CallableTools

Advanced tools for callable objects in Python.

Changelog · Report Bug · Request Feature

Table of Contents
  1. About The Project

  2. Getting Started

  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Provides advanced tools for callable objects in Python 3.x.

(back to top)

Built With

  • python-shield

(back to top)

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

Does not require any prerequisites.

Installation

  1. Clone the repo
git clone https://github.com/TahsinCr/python-callabletools.git
  1. Install PIP packages
pip install callabletools

(back to top)

Usage

Let'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

(back to top)

Roadmap

  • Add documentation.

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

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!

  1. Fork the Project

  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)

  3. Commit your Changes (git commit -m 'Add some AmazingFeature')

  4. Push to the Branch (git push origin feature/AmazingFeature)

  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Email: TahsinCr@outlook.com

X: @TahsinCrs

LinkedIn: TahsinCr

(back to top)

Acknowledgments

(back to top)

About

Advanced tools for callable objects in Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages