Skip to main content

A module that autofill functions with arguments

Project description

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:

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 .

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:

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

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?)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fillargs-1.0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fillargs-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file fillargs-1.0.1.tar.gz.

File metadata

  • Download URL: fillargs-1.0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for fillargs-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f0f2215f7ab72fa6e9853f51750883f49bd09a61bf56df42cee159dcf55d6990
MD5 9b5405968c49d386d3e5b0c2df81282a
BLAKE2b-256 d9da45ba41237eb6e46913bf7e58ef94bed4758c0f933bc034862a6a726062bd

See more details on using hashes here.

File details

Details for the file fillargs-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: fillargs-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for fillargs-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a39f4d52833b9da96844f0ab326624512777c7b818588e7766e669f6a5480348
MD5 a0d39c4282863d365ac192d8cb13c874
BLAKE2b-256 9dd3455083c66cb809e821158f8a502e960b1dc45c737f306972d11c41b3bbb3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page