Total Complexity | 5 |
Total Lines | 29 |
Duplicated Lines | 0 % |
1 | from coalib.misc.Decorators import ( |
||
5 | @generate_repr("line", "column") |
||
6 | @generate_ordering("line", "column") |
||
7 | class TextPosition: |
||
8 | |||
9 | @enforce_signature |
||
|
|||
10 | def __init__(self, line: (int, None)=None, column: (int, None)=None): |
||
11 | """ |
||
12 | Creates a new TextPosition object that represents the position inside |
||
13 | a string with line/column numbers. |
||
14 | |||
15 | :param line: The line in file or None, the first line is 1. |
||
16 | :param column: The column indicating the character. The first one |
||
17 | in a line is 1. |
||
18 | :raises TypeError: Raised when line or columns are no integers. |
||
19 | :raises ValueError: Raised when a column is set but line is None. |
||
20 | """ |
||
21 | if line is None and column is not None: |
||
22 | raise ValueError("A column can only be set if a line is set.") |
||
23 | |||
24 | self._line = line |
||
25 | self._column = column |
||
26 | |||
27 | @property |
||
28 | def line(self): |
||
29 | return self._line |
||
30 | |||
31 | @property |
||
32 | def column(self): |
||
33 | return self._column |
||
34 |