Completed
Pull Request — master (#33)
by
unknown
10:58
created

StarTuple()   A

Complexity

Conditions 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
dl 0
loc 14
rs 9.4285

1 Method

Rating   Name   Duplication   Size   Complexity  
A this_pack() 0 6 2
1
2
import collections
3
4
5
def StarTuple(name, named_fields, elements):
6
    named_tuple = collections.namedtuple(name, named_fields)
7
8
    def this_pack(self):
9
        packed = bytes()
10
        for key, value in self.__elements.items():
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like __elements was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
Unused Code introduced by
The variable key seems to be unused.
Loading history...
11
            packed += value.pack(self._asdict())
12
13
        return packed
14
15
    named_tuple.pack = this_pack
16
    named_tuple.__elements = elements
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like __elements was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
17
18
    return named_tuple
19