Total Complexity | 4 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | from os.path import relpath, abspath |
||
8 | @generate_repr("file", "line", "column") |
||
9 | @generate_ordering("file", "line", "column") |
||
10 | class SourcePosition(TextPosition): |
||
|
|||
11 | |||
12 | @enforce_signature |
||
13 | def __init__(self, file: str, line=None, column=None): |
||
14 | """ |
||
15 | Creates a new result position object that represents the position of a |
||
16 | result in the source code. |
||
17 | |||
18 | :param file: The filename. |
||
19 | :param line: The line in file or None, the first line is 1. |
||
20 | :param column: The column indicating the character. The first one |
||
21 | in a line is 1. |
||
22 | :raises TypeError: Raised when |
||
23 | - file is not a string or None. |
||
24 | - line or columns are no integers. |
||
25 | """ |
||
26 | TextPosition.__init__(self, line, column) |
||
27 | |||
28 | self._file = abspath(file) |
||
29 | |||
30 | @property |
||
31 | def file(self): |
||
32 | return self._file |
||
33 | |||
34 | def __json__(self, use_relpath=False): |
||
35 | _dict = get_public_members(self) |
||
36 | if use_relpath: |
||
37 | _dict['file'] = relpath(_dict['file']) |
||
38 | return _dict |
||
39 |