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)

you can pass also a argument environment:

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

It is possible to handle a instance or a class with the function 'handle_instance':

from fillargs import handle_instance
from yourclass import YourClass

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

#as a decorator
@handle_instance(reserved_args=args)
class YourClass:
    pass

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

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.0.tar.gz (5.5 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.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fillargs-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 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.0.tar.gz
Algorithm Hash digest
SHA256 6ab239fd900ea51e59e4aa9478ff0322468693e618e2746b29ac4fdc7036805d
MD5 3edf934ff17e7a852a1907787365ec98
BLAKE2b-256 8c3a46753a8141a439da833646b93ad2ed192019258471c385d1b06ac1f5d96c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fillargs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5319a75dfa5c80e29ceeeec440668ef1ae08993f73cca3a208bc2e65312c9fef
MD5 0fde2adca2184e9cd398f6f04ed7b2b5
BLAKE2b-256 4ee5ee6825427e47ec913ceb012d2d4e9e28efff43856c81b77767f5e1120979

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