Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hide_frames-1.0.0.tar.gz (38.7 kB view hashes)

Uploaded Source

Built Distribution

hide_frames-1.0.0-py3-none-any.whl (27.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page