fillargs


Namefillargs JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryA module that autofill functions with arguments
upload_time2024-11-27 14:00:02
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords function arguments automatic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
## About

If you are tired to provide the same arguments to a function or method, this library is for you. There is no neccessity passing 'verbose' each time. 
## Key Features

* Supports every combination of arguments(keyword,positional only,etc)
* Suitable for manipulating user-given methods of a class or instance

## How To Use
How to handle an single function:

```python
from fillargs import fill_function

default_args={"a":1,"b":2,"c":3}

@fill_function(reserved_args=default_args)
def fun(a,b,c=None,/d=None):
    print(a,b,c,d)

fun(1,2)
```
It is possible to define named configurations of variables, where you can access them by name .
```python
from fillargs.env import ArgEnv,getenv
from fillargs import fill_function
default_args={"a":1,"b":2,"c":3}

env=ArgEnv(default_args={"a":1,"b":2,"d":3},name="arg_env")
#or in case you have already define a environment
env=getenv(name="arg_env")
@fill_function(arg_env=env)
def fun(a,b,c=None,/d=None):
    print(a,b,c,d)


```
In case you dont provide arguments or environment , a default environment created by the user will be used:
```python
from fillargs.env import DefaultEnv
from fillargs import fill_function
args={"a":1,"b":2}
default_env=DefaultEnv(args)

@fill_function
def fun(*args,**kwds):
    print(args,kwds)

```

Finaly, it is possible to handle an instance or a class with the function 'handle_instance':
```python
from fillargs import handle_instance
from yourclass import YourClass

instance=YourClass()
#or
# YourClass=handle_instace(YourClass,..)
args={}
filled_instance=handle_instance(instace,reserved_args=args,on_names=["method1","method2"],strict=True)
filled_instance.method1()


```
Note that if you dont provide 'on_names' argument it will filter dunder and private methods and then it will decorate the remaining methods. Setting strict to False it will match each method's name that contains some name from on_names, else they must match exactly. Furthermore, a default argument will be replaced in case it exists in ArgEnv. So if your function defines a=1 and ArgEnv also have a value for variable 'a', the value from ArgEnv will be passed in the function call.

Also, you might use this library to provide the default arguments in each individual method of a class without write them in the method's definition( Why to do this?)







            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fillargs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "function, arguments, automatic",
    "author": null,
    "author_email": "Prodromos Mouratidis <prodromosm.97@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d9/da/45ba41237eb6e46913bf7e58ef94bed4758c0f933bc034862a6a726062bd/fillargs-1.0.1.tar.gz",
    "platform": null,
    "description": "\r\n## About\r\n\r\nIf you are tired to provide the same arguments to a function or method, this library is for you. There is no neccessity passing 'verbose' each time. \r\n## Key Features\r\n\r\n* Supports every combination of arguments(keyword,positional only,etc)\r\n* Suitable for manipulating user-given methods of a class or instance\r\n\r\n## How To Use\r\nHow to handle an single function:\r\n\r\n```python\r\nfrom fillargs import fill_function\r\n\r\ndefault_args={\"a\":1,\"b\":2,\"c\":3}\r\n\r\n@fill_function(reserved_args=default_args)\r\ndef fun(a,b,c=None,/d=None):\r\n    print(a,b,c,d)\r\n\r\nfun(1,2)\r\n```\r\nIt is possible to define named configurations of variables, where you can access them by name .\r\n```python\r\nfrom fillargs.env import ArgEnv,getenv\r\nfrom fillargs import fill_function\r\ndefault_args={\"a\":1,\"b\":2,\"c\":3}\r\n\r\nenv=ArgEnv(default_args={\"a\":1,\"b\":2,\"d\":3},name=\"arg_env\")\r\n#or in case you have already define a environment\r\nenv=getenv(name=\"arg_env\")\r\n@fill_function(arg_env=env)\r\ndef fun(a,b,c=None,/d=None):\r\n    print(a,b,c,d)\r\n\r\n\r\n```\r\nIn case you dont provide arguments or environment , a default environment created by the user will be used:\r\n```python\r\nfrom fillargs.env import DefaultEnv\r\nfrom fillargs import fill_function\r\nargs={\"a\":1,\"b\":2}\r\ndefault_env=DefaultEnv(args)\r\n\r\n@fill_function\r\ndef fun(*args,**kwds):\r\n    print(args,kwds)\r\n\r\n```\r\n\r\nFinaly, it is possible to handle an instance or a class with the function 'handle_instance':\r\n```python\r\nfrom fillargs import handle_instance\r\nfrom yourclass import YourClass\r\n\r\ninstance=YourClass()\r\n#or\r\n# YourClass=handle_instace(YourClass,..)\r\nargs={}\r\nfilled_instance=handle_instance(instace,reserved_args=args,on_names=[\"method1\",\"method2\"],strict=True)\r\nfilled_instance.method1()\r\n\r\n\r\n```\r\nNote that if you dont provide 'on_names' argument it will filter dunder and private methods and then it will decorate the remaining methods. Setting strict to False it will match each method's name that contains some name from on_names, else they must match exactly. Furthermore, a default argument will be replaced in case it exists in ArgEnv. So if your function defines a=1 and ArgEnv also have a value for variable 'a', the value from ArgEnv will be passed in the function call.\r\n\r\nAlso, you might use this library to provide the default arguments in each individual method of a class without write them in the method's definition( Why to do this?)\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A module that autofill functions with arguments",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [
        "function",
        " arguments",
        " automatic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9dd3455083c66cb809e821158f8a502e960b1dc45c737f306972d11c41b3bbb3",
                "md5": "a0d39c4282863d365ac192d8cb13c874",
                "sha256": "a39f4d52833b9da96844f0ab326624512777c7b818588e7766e669f6a5480348"
            },
            "downloads": -1,
            "filename": "fillargs-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a0d39c4282863d365ac192d8cb13c874",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6284,
            "upload_time": "2024-11-27T14:00:01",
            "upload_time_iso_8601": "2024-11-27T14:00:01.315254Z",
            "url": "https://files.pythonhosted.org/packages/9d/d3/455083c66cb809e821158f8a502e960b1dc45c737f306972d11c41b3bbb3/fillargs-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d9da45ba41237eb6e46913bf7e58ef94bed4758c0f933bc034862a6a726062bd",
                "md5": "9b5405968c49d386d3e5b0c2df81282a",
                "sha256": "f0f2215f7ab72fa6e9853f51750883f49bd09a61bf56df42cee159dcf55d6990"
            },
            "downloads": -1,
            "filename": "fillargs-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9b5405968c49d386d3e5b0c2df81282a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5600,
            "upload_time": "2024-11-27T14:00:02",
            "upload_time_iso_8601": "2024-11-27T14:00:02.583702Z",
            "url": "https://files.pythonhosted.org/packages/d9/da/45ba41237eb6e46913bf7e58ef94bed4758c0f933bc034862a6a726062bd/fillargs-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-27 14:00:02",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "fillargs"
}
        
Elapsed time: 0.38579s