Base type for objects that are valid as error message locations.
| 87 | |
| 88 | |
| 89 | class Context: |
| 90 | """Base type for objects that are valid as error message locations.""" |
| 91 | |
| 92 | __slots__ = ("line", "column", "end_line", "end_column") |
| 93 | |
| 94 | def __init__(self, line: int = -1, column: int = -1) -> None: |
| 95 | self.line = line |
| 96 | self.column = column |
| 97 | self.end_line: int | None = None |
| 98 | self.end_column: int | None = None |
| 99 | |
| 100 | def set_line( |
| 101 | self, |
| 102 | target: Context | int, |
| 103 | column: int | None = None, |
| 104 | end_line: int | None = None, |
| 105 | end_column: int | None = None, |
| 106 | ) -> None: |
| 107 | """If target is a node, pull line (and column) information |
| 108 | into this node. If column is specified, this will override any column |
| 109 | information coming from a node. |
| 110 | """ |
| 111 | if isinstance(target, int): |
| 112 | self.line = target |
| 113 | else: |
| 114 | self.line = target.line |
| 115 | self.column = target.column |
| 116 | self.end_line = target.end_line |
| 117 | self.end_column = target.end_column |
| 118 | |
| 119 | if column is not None: |
| 120 | self.column = column |
| 121 | |
| 122 | if end_line is not None: |
| 123 | self.end_line = end_line |
| 124 | |
| 125 | if end_column is not None: |
| 126 | self.end_column = end_column |
| 127 | |
| 128 | |
| 129 | if TYPE_CHECKING: |
no outgoing calls
no test coverage detected
searching dependent graphs…