mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user