Add type annotations to start- and end-pos attributes

These are frequently used within consuming code, so having annotations
avoids others needing to work around mypy errors from them.
This commit is contained in:
Peter Law
2021-01-03 15:57:35 +00:00
parent 14c88c1f4b
commit 0e20c33c21
4 changed files with 23 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ tests of pydocstyle.
import difflib
import re
from functools import total_ordering
from typing import Iterator, Tuple
import parso
from parso.utils import python_bytes_to_unicode
@@ -13,7 +14,7 @@ from parso.utils import python_bytes_to_unicode
@total_ordering
class WantedIssue:
def __init__(self, code, line, column):
def __init__(self, code: str, line: int, column: int) -> None:
self.code = code
self._line = line
self._column = column
@@ -21,18 +22,18 @@ class WantedIssue:
def __eq__(self, other):
return self.code == other.code and self.start_pos == other.start_pos
def __lt__(self, other):
def __lt__(self, other: 'WantedIssue') -> bool:
return self.start_pos < other.start_pos or self.code < other.code
def __hash__(self):
def __hash__(self) -> int:
return hash(str(self.code) + str(self._line) + str(self._column))
@property
def start_pos(self):
def start_pos(self) -> Tuple[int, int]:
return self._line, self._column
def collect_errors(code):
def collect_errors(code: str) -> Iterator[WantedIssue]:
for line_nr, line in enumerate(code.splitlines(), 1):
match = re.match(r'(\s*)#: (.*)$', line)
if match is not None: