Skip to main content

Simple library for patching function inner scope

Project description

Argumentize decorator allow convert any function into kind a 'pure' function that eliminate all globals and closures as a implicit dependencies but allow them to be passed as regular key-value arguments.

Here is a simple example:

from argumentize import argumentize

x = 100


def foo(a, b, c):
    return a + b + c + x


foo = argumentize(foo)

foo(1, 2, 3)  # 106
foo(1, 2, 3, x=10)  # 16

Argumentized can be any dependency not only a variable. Here is how you can use it with a function:

from argumentize import argumentize


def foo(a, b, c):
    return a + b + c


def bar(a, b, c, d):
    return foo(a, b, c) + d


bar = argumentize(bar)

bar(1, 2, 3, 4)  # 10

bar(1, 2, 3, 4, foo=lambda a, b, c: a * b * c)  # 24

Argumentize can be used as a decorator:

from argumentize import argumentize


@argumentize
def foo(a, b, c):
    return a + b + c


foo(1, 2, 3)  # 6

foo(1, 2, 3, b=10)  # 14

If you does not provide the value for argumented argument the default variable (either from globals or from the function closure) will be used

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

argumentize-1.0.2.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

argumentize-1.0.2-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file argumentize-1.0.2.tar.gz.

File metadata

  • Download URL: argumentize-1.0.2.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for argumentize-1.0.2.tar.gz
Algorithm Hash digest
SHA256 d553f7236bdee2e47e79528f9aef15e61c606912fdf9f0782ea4e7393255b7dd
MD5 21b6a1ce3e4c5a3ded079a87558b9fbc
BLAKE2b-256 2e03ce287b00adb8d68fbff9f473498eec3987df89ea1ffbc2cbb4eed1371eb1

See more details on using hashes here.

File details

Details for the file argumentize-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: argumentize-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for argumentize-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 452535b74f756f7ebc06abbf9753c0c993ef69c424cfdb063c22715f7c240c7d
MD5 305a306d5b6e1d690866b49528fea39e
BLAKE2b-256 ed7fd3da190a2ee2434aa362ebd49766ce0a5d20a7082562e5c5ba3e92ddf192

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