Test Failed
Push — master ( a5ee34...588b1f )
by Justin M.
34s queued 10s
created

pynvim.util.format_exc_skip()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 2
1
"""Shared utility functions."""
2
3 6
import sys
4 6
from traceback import format_exception
5
6
7 6
def format_exc_skip(skip, limit=None):
8
    """Like traceback.format_exc but allow skipping the first frames."""
9 6
    etype, val, tb = sys.exc_info()
10 6
    for i in range(skip):
11 6
        tb = tb.tb_next
12 6
    return (''.join(format_exception(etype, val, tb, limit))).rstrip()
13
14
15
# Taken from SimpleNamespace in python 3
16 6
class Version:
17
    """Helper class for version info."""
18
19 6
    def __init__(self, **kwargs):
20
        """Create the Version object."""
21 6
        self.__dict__.update(kwargs)
22
23 6
    def __repr__(self):
24
        """Return str representation of the Version."""
25
        keys = sorted(self.__dict__)
26
        items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable k does not seem to be defined.
Loading history...
27
        return "{}({})".format(type(self).__name__, ", ".join(items))
28
29 6
    def __eq__(self, other):
30
        """Check if version is same as other."""
31
        return self.__dict__ == other.__dict__
32
33
34 6
def get_client_info(kind, type_, method_spec):
35
    """Returns a tuple describing the client."""
36 6
    name = "python{}-{}".format(sys.version_info[0], kind)
37 6
    attributes = {"license": "Apache v2",
38
                  "website": "github.com/neovim/pynvim"}
39 6
    return (name, VERSION.__dict__, type_, method_spec, attributes)
40
41
42
VERSION = Version(major=0, minor=4, patch=0, prerelease='')
43