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 inspect.signature(bar) == inspect.signature(foo)

print(inspect.signature(bar))
# (a, b, c)

print(inspect.getdoc(bar))
# This is the docstring for bar.

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
import inspect


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."""


print(inspect.getdoc(bar))
# This is the docstring for foo.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: delegatefn-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 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.0.tar.gz
Algorithm Hash digest
SHA256 c035ebce0431d3c467013496f1f70c68dcfc1b8a952bf5a381eb245ef3a17606
MD5 d7598d35869138aad5aca371eb1e0ffc
BLAKE2b-256 97293d8b294b2472938543802dcc2eacd5326d006aba7c72b2892c3fdb72d490

See more details on using hashes here.

File details

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

File metadata

  • Download URL: delegatefn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2707e52eb45ebe244f8287ede821f4633275dde5f7c000b85becd2c4123d94aa
MD5 d818ca174096565286d567106d3d7fc7
BLAKE2b-256 f520420eb323a591e37e99359f54556a7fa14db681fbd460ad962f713e3a7baf

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