Skip to main content

Signature-preserving function delegation

Project description

A tiny utility for preserving signature information (parameter names, annotations, and docstrings) when delegating one function to another.

Works for keyword arguments only; positional arguments are not supported.

Installation

pip install delegatefn

Usage

from delegatefn import delegate
import inspect

def foo(a, b, c):
    """This is the docstring for foo."""

@delegate(foo)
def bar(**kwargs):
    """This is the docstring for bar."""

assert foo.__doc__ == bar.__doc__ == "This is the docstring for foo."
assert inspect.signature(bar).parameters.keys() == {"a", "b", "c"}

Limitations

Unfortunately, there isn't an easy way to combine docstrings from multiple functions. Instead, delegate lets you decide which function's docstring to use.

from delegatefn import delegate

def foo(a, b, c):
    """This is the docstring for foo."""

@delegate(foo, delegate_docstring=False)
def bar(**kwargs):
    """This is the docstring for bar."""

assert foo.__doc__ != bar.__doc__ == "This is the docstring for bar."

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

delegatefn-0.1.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

delegatefn-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file delegatefn-0.1.1.tar.gz.

File metadata

  • Download URL: delegatefn-0.1.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.1 Darwin/22.1.0

File hashes

Hashes for delegatefn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 83cca873c4a11acfbd1ff7ca0866a3fe7e593edeeca9a19645e5a9a4e3afb948
MD5 5c6561a34e171788b6a6b62d27fae67e
BLAKE2b-256 ca7a7dfbb37e9889838de1ca2aa89d06e85d14017315df1f3318dd606dbc0e2a

See more details on using hashes here.

File details

Details for the file delegatefn-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: delegatefn-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.1 Darwin/22.1.0

File hashes

Hashes for delegatefn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc4cea9bcacc74b0d37597b2e1b5839c6b673db214eb19bb75e1112f8cf0dc82
MD5 1e04b19b2c2fd6d96d93aa720919616c
BLAKE2b-256 c7c865bad14a11797ab352b4425adf7ed500aeb135a552ec72b11fba1654ca38

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