Completed
Pull Request — master (#221)
by
unknown
47:03 queued 22:03
created

format_exc_msg()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
"""Shared utility functions."""
2
3 5
import sys
4 5
from traceback import format_exception
5
6
7 5
def format_exc_skip(skip, limit=None):
8
    """Like traceback.format_exc but allow skipping the first frames."""
9 5
    type, val, tb = sys.exc_info()
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
10 5
    for i in range(skip):
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
11 5
        tb = tb.tb_next
12 5
    return ('\n'.join(format_exception(type, val, tb, limit))).rstrip()
13
14
15
def format_exc_msg(skip=1, limit=None):
0 ignored issues
show
Unused Code introduced by
The argument limit seems to be unused.
Loading history...
16 5
    """Format ``exc`` to be used in error messages."""
17
    _, exc, _ = sys.exc_info()
18
    return "{!r}\n{}\n\n".format(exc, format_exc_skip(skip))
19
20 5
21
# Taken from SimpleNamespace in python 3
22 5
class Version:
23
24 5
    """Helper class for version info."""
25
26
    def __init__(self, **kwargs):
27
        """Create the Version object."""
28
        self.__dict__.update(kwargs)
29
30 5
    def __repr__(self):
31
        """Return str representation of the Version."""
32
        keys = sorted(self.__dict__)
33
        items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
34
        return "{}({})".format(type(self).__name__, ", ".join(items))
35
36
    def __eq__(self, other):
37
        """Check if version is same as other."""
38
        return self.__dict__ == other.__dict__
39