Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

#########
staticargs
#########
**A clean way to work around mutable default arguments in python functions**

Get staticargs
=============

staticargs supports Python 2 and 3. Tests are run for 2.7 and 3.4

.. code-block:: shell

pip install staticargs

Run the tests
=============
You must install tox, then run:

.. code-block:: shell

git clone https://github.com/HurricaneLabs/staticargs.git
cd staticargs
tox

Example
--------

First view the problem we are going to solve:

.. code-block:: python

>>> def append_cat(cats=[]):
... cats.append("cat")
... return cats
...
>>> print(append_cat())
['cat']
>>> print(append_cat())
['cat', 'cat']
>>> print(append_cat())
['cat', 'cat', 'cat']
>>>

Well that's not good! Notice how even though we are appending "cat" only once, the number of items in the list returned gets bigger each time. Learn more about this problem and some other Python gotchas by watching this amazing presentation from PyCon 2015 (this specific problem is discussed at 8:04): https://youtu.be/sH4XF6pKKmk

staticargs solves this problem for you:

.. code-block:: python

>>> from staticargs import staticargs
>>> import random
>>>
>>> @staticargs
... def append_cat(cats=[]):
... #I love cats
... cats.append("cat")
... return cats
...
>>> print(append_cat())
['cat']
>>> print(append_cat())
['cat']
>>> print(append_cat())
['cat']
>>>
>>> @staticargs
... def store_dog(dogs={}):
... #Dogs are OK I guess
... dog_name = random.choice(["rufus", "muffins", "scooby"])
... dogs[dog_name] = "good boy"
... return dogs
...
>>> print(store_dog())
{'muffins': 'good boy'}
>>> print(store_dog())
{'scooby': 'good boy'}
>>> print(store_dog())
{'rufus': 'good boy'}
>>>

Release files for staticargs 1.0.0rc3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for staticargs 1.0.0rc3
File Size Uploaded
staticargs-1.0.0rc3.tar.gz 2.7 kB Details

Release files / staticargs-1.0.0rc3.tar.gz

Download URL staticargs-1.0.0rc3.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1384c975653e0535035a0786e855cd35e06e94d51e88b70593feafce72f0db6b
BLAKE2b-256 checksum
How to use checksums
f814e1b5e62c38e7207a06ea9fafdfbc1907967ab1149f315502e52fed8d552f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0rc3 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page