====================================================================
merge_args — merge signatures of two functions with Advanced Hackery
====================================================================
.. image:: https://travis-ci.org/Kwpolska/merge_args.svg?branch=master
:target: https://travis-ci.org/Kwpolska/merge_args
This small library uses Advanced Python Hackery to change the signature of a
function to be a mixture of itself and a function that it wraps. It’s like
``functools.wraps``, but it allows the wrapped function to add its own
arguments into the mix.
Usage
-----
.. code:: python
from merge_args import merge_args
def old(foo, bar):
"""This is old's docstring."""
print(foo, bar)
return foo + bar
@merge_args(old)
def new(prefix, foo, *args, **kwargs):
return old(prefix + foo, *args, **kwargs)
If you then run ``help(new)``, this is the output:
.. code:: text
Help on function new in module __main__:
new(prefix, foo, bar)
This is old's docstring.
How it works?
-------------
I wrote a detailed blog post, describing the ins and outs of how this package works:
https://chriswarrick.com/blog/2018/09/20/python-hackery-merging-signatures-of-two-python-functions/
This module was inspired by F4D3C0D3 on #python (formerly on freenode IRC).
License
-------
Copyright © 2018-2022, Chris Warrick.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the author of this software nor the names of
contributors to this software may be used to endorse or promote
products derived from this software without specific prior written
consent.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Raw data
{
"_id": null,
"home_page": "https://github.com/Kwpolska/merge_args",
"name": "merge-args",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "merge_args",
"author": "Chris Warrick",
"author_email": "chris@chriswarrick.com",
"download_url": "https://files.pythonhosted.org/packages/cd/6e/7dc4bd3583b991b7e131c948ede058f6678afa9aea6b88961d507b4fa951/merge_args-0.1.5.tar.gz",
"platform": "any",
"description": "====================================================================\nmerge_args \u2014 merge signatures of two functions with Advanced Hackery\n====================================================================\n\n.. image:: https://travis-ci.org/Kwpolska/merge_args.svg?branch=master\n :target: https://travis-ci.org/Kwpolska/merge_args\n\nThis small library uses Advanced Python Hackery to change the signature of a\nfunction to be a mixture of itself and a function that it wraps. It\u2019s like\n``functools.wraps``, but it allows the wrapped function to add its own\narguments into the mix.\n\nUsage\n-----\n\n.. code:: python\n\n from merge_args import merge_args\n\n def old(foo, bar):\n \"\"\"This is old's docstring.\"\"\"\n print(foo, bar)\n return foo + bar\n\n @merge_args(old)\n def new(prefix, foo, *args, **kwargs):\n return old(prefix + foo, *args, **kwargs)\n\nIf you then run ``help(new)``, this is the output:\n\n.. code:: text\n\n Help on function new in module __main__:\n\n new(prefix, foo, bar)\n This is old's docstring.\n\nHow it works?\n-------------\n\nI wrote a detailed blog post, describing the ins and outs of how this package works:\n\nhttps://chriswarrick.com/blog/2018/09/20/python-hackery-merging-signatures-of-two-python-functions/\n\nThis module was inspired by F4D3C0D3 on #python (formerly on freenode IRC).\n\nLicense\n-------\nCopyright \u00a9 2018-2022, Chris Warrick.\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n1. Redistributions of source code must retain the above copyright\n notice, this list of conditions, and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions, and the following disclaimer in the\n documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the author of this software nor the names of\n contributors to this software may be used to endorse or promote\n products derived from this software without specific prior written\n consent.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n",
"bugtrack_url": null,
"license": "3-clause BSD",
"summary": "Merge signatures of two functions with Advanced Hackery.",
"version": "0.1.5",
"project_urls": {
"Homepage": "https://github.com/Kwpolska/merge_args"
},
"split_keywords": [
"merge_args"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "84dd8b9bf1b36927707ae04ec6f8e63f36cdce8c32cea2ed3ecffb04565264d0",
"md5": "9383e5c148a7b5b37de7669109d2a047",
"sha256": "f296a2dd9156dd055e3f540f0fb5784b94933457a4e0e8d0031a763c26bf24a8"
},
"downloads": -1,
"filename": "merge_args-0.1.5-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "9383e5c148a7b5b37de7669109d2a047",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 6040,
"upload_time": "2022-11-19T12:59:16",
"upload_time_iso_8601": "2022-11-19T12:59:16.778834Z",
"url": "https://files.pythonhosted.org/packages/84/dd/8b9bf1b36927707ae04ec6f8e63f36cdce8c32cea2ed3ecffb04565264d0/merge_args-0.1.5-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cd6e7dc4bd3583b991b7e131c948ede058f6678afa9aea6b88961d507b4fa951",
"md5": "78ad4ff9f94a581880f1ac1c4ef2bbfb",
"sha256": "ad37e6c4c7f1eadda5a0564b26ca7d56f8a37f232f5c5c46f9ef93d352757c23"
},
"downloads": -1,
"filename": "merge_args-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "78ad4ff9f94a581880f1ac1c4ef2bbfb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5986,
"upload_time": "2022-11-19T12:59:18",
"upload_time_iso_8601": "2022-11-19T12:59:18.722562Z",
"url": "https://files.pythonhosted.org/packages/cd/6e/7dc4bd3583b991b7e131c948ede058f6678afa9aea6b88961d507b4fa951/merge_args-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-11-19 12:59:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Kwpolska",
"github_project": "merge_args",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "merge-args"
}