Hide ugly frames in your wrappers
Project description
hide_frames
Ever had nested wrappers (probably from many libraries) ... and your traceback look messy? There's just func(*args, **kwargs)
everywhere!
Not anymore, using hide_frames
, you can (ironically) use a simple decorator to hide your ugly frames!
Installation
pip install hide_frames
Example
Suppose we have a wrapper:
def useless(f):
def wrapped_function(*args, **kwargs):
return f(*args, **kwargs)
return wrapped_function
If we have a function that raises an exception and we wrap it:
@useless
def oops():
raise Exception
We would get an ugly traceback if we call it:
Traceback (most recent call last):
File "myfile.py", line 10, in <module>
oops()
File "myfile.py", line 3, in wrapped_function
return f(*args, **kwargs) # <--- ugly
^^^^^^^^^^^^^^^^^^
File "myfile.py", line 8, in oops
raise Exception
Exception
We can use the hide_frame decorator to modify our useless
decorator:
def useless(f):
@hide_frame # <-- important
def wrapped_function(*args, **kwargs):
return f(*args, **kwargs)
return wrapped_function
Now, our traceback looks like this:
Traceback (most recent call last):
File "myfile.py", line 13, in <module>
oops()
File "myfile.py", line 11, in oops
raise Exception
Exception
Hooray! No more f(*args, **kwargs)
!
The best part: it works with any number of decorators!
If you have more than one frame that needs to be hidden, use hide_nframes()
(There's another simple example in test.py
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for hide_frames-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a23c70097dd20ba2f4e0a7cb28a7e434a88b778faf6f6302abe17c8db9671a5c |
|
MD5 | 5f6ebae9be2873c868911bb7ed979a7d |
|
BLAKE2b-256 | e07757a3410ff815e331cb5a407536f815e6e9a6bca148a424e664387d85a8f9 |