Completed
Pull Request — master (#2624)
by
unknown
01:54
created

TextPosition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 5
1
from coala_utils.decorators import (
2
    enforce_signature, generate_ordering, generate_repr)
3
4
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