hashable_node_snapshot   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A HashableNodeSnapshot.__init__() 0 8 1
A HashableNodeSnapshot.__eq__() 0 10 3
A HashableNodeSnapshot.__hash__() 0 2 1
1
from overpy import Node  # type: ignore
2
3
4
# future: embed this into overpy.Node
5
class HashableNodeSnapshot(Node):
6
    def __init__(self, node: Node):
7
        super().__init__(
8
            node_id=node.id,
9
            lat=node.lat,
10
            lon=node.lon,
11
            attributes=node.attributes,
12
            result=node._result,
13
            tags=node.tags,
14
        )
15
16
    def __hash__(self) -> int:
17
        return hash((self.id, self.lat, self.lon, frozenset(self.tags.items())))
18
19
    def __eq__(self, other: object) -> bool:
20
        if isinstance(other, HashableNodeSnapshot) or isinstance(other, Node):
21
            return (self.id, self.lat, self.lon, self.tags.items()) == (
22
                other.id,
23
                other.lat,
24
                other.lon,
25
                other.tags.items(),
26
            )
27
28
        return NotImplemented
29