Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.6%) to scientific vocabulary
Repository
Keyword arguments handled
Basic Info
- Host: GitHub
- Owner: egpbos
- License: apache-2.0
- Language: Python
- Default Branch: main
- Size: 104 KB
Statistics
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 8
- Releases: 2
Metadata Files
README.md
kwandl: Keyword arguments handled
Installation
Install kwandl using pip:
console
python3 -m pip install kwandl
To install the most recent development version directly from the GitHub repository run:
console
python3 -m pip install git+https://github.com/egpbos/kwandl.git
Usage
kwandl is essentially a box of magic tricks to make working with kwargs smoother.
Forward passing only relevant kwargs
Say you have a function top which takes **kwargs and passes them on to ding and boop:
python
def top(**kwargs):
ding(**kwargs)
boop(**kwargs)
Only problem is: ding and boop have different sets of keyword arguments:
```python
def ding(dingo=1, dinga=2):
...
def boop(boopie=3, boonk=4):
...
``
This meanstop(dingo="blurg", boonk=None)will fail with aTypeError, becauseboonkwill be passed todinganddingowill be passed toboop`, both of which are invalid.
kwandl solves this for you with one simple decorator:
python
@kwandl.forward
def top(**kwargs):
ding(**kwargs)
boop(**kwargs)
This Just Works™.
It does so by modifying the abstract syntax tree (AST) of the function calls with kwargs as argument so that kwargs is effectively replaced by kwandl.get_kwargs_applicable_to_function(ding, kwargs) (or boop instead of ding depending on the calling function).
An alternative way to use this kwandl functionality then is to use get_kwargs_applicable_to_function directly:
python
def top(**kwargs):
ding(**kwandl.get_kwargs_applicable_to_function(ding, kwargs))
boop(**kwandl.get_kwargs_applicable_to_function(boop, kwargs))
Note, however, that @kwandl.forward does a bit more: it also checks whether kwargs contains keyword arguments that are a match to neither ding nor boop and raises a TypeError if so.
A complete alternative notation for @kwandl.forward would then be:
```python def top(**kwargs): dingkwargs = kwandl.getkwargsapplicabletofunction(ding, kwargs) boopkwargs = kwandl.getkwargsapplicabletofunction(boop, kwargs)
unexpected_keywords = set(kwargs) - set(ding_kwargs) - set(boop_kwargs)
if unexpected_keywords:
raise TypeError(f"top() got an unexpected keyword argument '{unexpected_keywords.pop()}'")
ding(**ding_kwargs)
boop(**boop_kwargs)
``` The motivation behind this package should now become clearer: the amount of boilerplate necessary to solve what in my mind should not be such a huge problem is ... well, huge.
Documentation
For more details, see the full documentation on Readthedocs.
Contributing
If you want to contribute to the development of kwandl,
have a look at the contribution guidelines.
Credits
This package was created with Cookiecutter and the NLeSC/python-template.
Owner
- Name: Patrick Bos
- Login: egpbos
- Kind: user
- Location: Amsterdam
- Company: Netherlands eScience Center
- Website: http://egpbos.nl
- Repositories: 66
- Profile: https://github.com/egpbos
Technology Lead (software quality), freelance data scientist, cosmologist / scientific computing, HPC, data science, Bayesian inference
Citation (CITATION.cff)
# YAML 1.2
---
cff-version: "1.1.0"
title: "kwandl"
authors:
-
family-names: Bos
given-names: E. G. Patrick
orcid: "https://orcid.org/0000-0002-6033-960X"
date-released: 2022-03-11
# doi: <insert your DOI here>
version: "0.2.0"
repository-code: "https://github.com/egpbos/kwandl"
keywords:
- kwargs
- python
message: "If you use this software, please cite it using these metadata."
license: Apache-2.0
GitHub Events
Total
Last Year
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| E. G. Patrick Bos | e****s@g****m | 58 |
| NLeSC Python template | n****e | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 13
- Total pull requests: 0
- Average time to close issues: 22 days
- Average time to close pull requests: N/A
- Total issue authors: 2
- Total pull request authors: 0
- Average comments per issue: 0.38
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 5
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- egpbos (8)
- github-actions[bot] (5)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 10 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 2
- Total maintainers: 1
pypi.org: kwandl
Keyword arguments handled
- Homepage: https://github.com/egpbos/kwandl
- Documentation: https://kwandl.readthedocs.io/
- License: Apache Software License
-
Latest release: 0.2.0
published almost 4 years ago