# Example
Imagine you have the following code (as featured in the [Hypothesis docs](https://hypothesis.readthedocs.io/en/latest/quickstart.html)):
```py
def encode(input_string):
count = 1
prev = ''
lst = []
for character in input_string:
if character != prev:
if prev:
entry = (prev, count)
lst.append(entry)
count = 1
prev = character
else:
count += 1
else:
entry = (character, count)
lst.append(entry)
return lst
```
It has a fatal flaw: it crashes if you give it an empty string:
```
>>> encode('')
Traceback (most recent call last):
...
UnboundLocalError: local variable 'character' referenced before assignment
```
To hide the bug, simply apply the `hush` decorator:
```py
from hushbugger import hush
@hush
def encode(input_string):
count = 1
prev = ''
lst = []
for character in input_string:
if character != prev:
if prev:
entry = (prev, count)
lst.append(entry)
count = 1
prev = character
else:
count += 1
else:
entry = (character, count)
lst.append(entry)
return lst
```
Now it works!
```
>>> encode('')
[]
```
# How it works
If the function raises an exception, its bytecode is disassembled and inspected to look for return statements. If a constant value is returned (e.g. `return True`), that value is used. If a variable is returned (e.g. `return x`), and that variable had a value at the time of the exception, that value is used.
If no usable return statements are found, a `Dummy` object is returned. It responds to almost any operation you throw at it (calling it, adding it, iterating over it, etcetera), so hopefully it gets discarded before visibly breaking anything. Its `repr` is also disguised, as if it belonged to a random module.
```py
@hush
def double(x):
return 2 * x
```
```
>>> double([1, 2, 3])
[1, 2, 3, 1, 2, 3]
>>> ret = double({})
>>> ret
<errno.Coalescer object at 0x7f96708cb438>
>>> len(list(ret.invert()))
51
```
# Installing
```
pip install hushbugger
```
Metadata
Release files for hushbugger 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hushbugger-0.0.1.tar.gz | 3.2 kB | Without provenance | Details for hushbugger-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hushbugger-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for hushbugger-0.0.1-py3-none-any.whl |
Total release size: 8.3 kB
Release files / hushbugger-0.0.1.tar.gz
| Download URL | hushbugger-0.0.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
998e5027b61945c3bcd7341ab93052dc521aaeb15c7251069f8c077b16d89306
|
|
BLAKE2b-256 checksum How to use checksums |
605b156a8db230ef79ba0c67ad1ac97a55006c71aea954d53afc23878aaa9019
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.1 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
|
Release files / hushbugger-0.0.1-py3-none-any.whl
| Download URL | hushbugger-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
130732b6fda7f744ce28583f9a1b33cf335856945d10f52bfcef3c24e77156d3
|
|
BLAKE2b-256 checksum How to use checksums |
d62bbb30ff6951591c178d81ba262bd197d1da59eeb151edfb25a64069eecc81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.1 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
|
Security for hushbugger 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.