-
Notifications
You must be signed in to change notification settings - Fork 19
/
meta_key.py
27 lines (21 loc) · 1 KB
/
meta_key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import Tuple, Union, Optional
from meta_row import MetaRow
class MetaKey:
def __init__(self,
meta_file_path: Union[MetaRow, str],
line_start: Optional[int] = None,
line_end: Optional[int] = None):
if isinstance(meta_file_path, MetaRow):
self.key = (meta_file_path.FilePath, meta_file_path.LineStart, meta_file_path.LineEnd)
elif isinstance(meta_file_path, str) and isinstance(line_start, int) and isinstance(line_end, int):
if line_start > line_end:
raise RuntimeError(f"Wrong start-end values {line_start} > {line_end}")
self.key = (meta_file_path, line_start, line_end)
else:
raise RuntimeError(f"Wrong values {meta_file_path}, {line_start}, {line_end}")
def __hash__(self):
return hash(self.key)
def __eq__(self, other: 'MetaKey'):
return self.key == other.key
def __ne__(self, other: 'MetaKey'):
return not (self == other)