Skip to content

Commit

Permalink
fix: more typehint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
5j9 committed Oct 17, 2024
1 parent 78c96fb commit f0d8ac8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tests/test_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from wikitextparser import WikiText, parse

# noinspection PyProtectedMember
from wikitextparser._spans import PF_TL_FINDITER, parse_to_spans
from wikitextparser._spans import PF_TL_FINDITER, TypeToSpans, parse_to_spans


def bytearray_parse_to_spans(bytes_: bytes) -> dict[str, list[list[int]]]:
def bytearray_parse_to_spans(bytes_: bytes) -> TypeToSpans:
return {
k: [i[:2] for i in v] # no need for match and byte_array
for k, v in parse_to_spans(bytearray(bytes_)).items()
Expand Down
23 changes: 11 additions & 12 deletions wikitextparser/_cell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from typing import Match, MutableSequence
from typing import MutableSequence

from regex import DOTALL, VERBOSE
from regex import DOTALL, VERBOSE, Match

from ._spans import ATTRS_MATCH
from ._spans import ATTRS_MATCH, TypeToSpans
from ._tag import SubWikiTextWithAttrs
from ._wikitext import rc

Expand Down Expand Up @@ -148,13 +148,12 @@ def __init__(
self,
string: str | MutableSequence[str],
header: bool = False,
_type_to_spans: dict[str, list[list[int]]] = None,
_span: int = None,
_type: int = None,
_match: Match = None,
_attrs_match: Match = None,
_type_to_spans: TypeToSpans | None = None,
_span: list | None = None,
_type: int | None = None,
_match: Match | None = None,
_attrs_match: Match | None = None,
) -> None:
"""Initialize the object."""
super().__init__(string, _type_to_spans, _span, _type)
self._header = header
if _match:
Expand All @@ -177,7 +176,7 @@ def __init__(
self._attrs_match_cache = self._match_cache = None, None

@property
def _match(self):
def _match(self) -> Match[bytes]:
"""Return the match object for the current tag. Cache the result.
Be extra careful when using this property. The position of match
Expand All @@ -187,7 +186,7 @@ def _match(self):
cache_match, cache_string = self._match_cache
string = self.string
if cache_string == string:
return cache_match
return cache_match # type: ignore
shadow = self._shadow
if shadow[0] == 10: # ord('\n')
m = NEWLINE_CELL_MATCH(shadow)
Expand All @@ -198,7 +197,7 @@ def _match(self):
m = INLINE_NONHAEDER_CELL_MATCH(shadow)
self._match_cache = m, string
self._attrs_match_cache = None, None
return m
return m # type: ignore

@property
def value(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion wikitextparser/_wikitext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ def _lists_shadow_ss(self) -> tuple[bytearray, int]:
return self._shadow, self._span_data[0]

def get_lists(
self, pattern: str | tuple[str, ...] = (r'\#', r'\*', '[:;]')
self, pattern: str | Iterable[str] = (r'\#', r'\*', '[:;]')
) -> list[WikiList]:
r"""Return a list of WikiList objects.
Expand Down

0 comments on commit f0d8ac8

Please sign in to comment.