HashableNodeSnapshot.__eq__()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
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