Skip to content

Commit

Permalink
pass selection to TextPositionSet init in list
Browse files Browse the repository at this point in the history
for type checker
  • Loading branch information
mscarey committed Nov 6, 2023
1 parent bdf142c commit 15b846f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions anchorpoint/textselectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import re

from typing import List, Optional, Sequence, Tuple, Union
from typing import List, Optional, Sequence, Tuple, TypeVar, Union
from anchorpoint.textsequences import TextPassage, TextSequence
from ranges import Range, RangeSet, Inf
from ranges._helper import _InfiniteValue
Expand Down Expand Up @@ -251,6 +251,9 @@ def suffix_regex(self):
return (r"\s*" + re.escape(self.suffix.strip())) if self.suffix else ""


ST = TypeVar("ST")


class TextPositionSelector(BaseModel):
"""
Describes a textual segment by start and end positions.
Expand Down Expand Up @@ -687,7 +690,7 @@ def quote_selectors_are_in_list(

@field_validator("positions", mode="before")
@classmethod
def is_sequence(cls, v: list[TextPositionSelector]):
def is_sequence(cls, v: ST | Sequence[ST]) -> Sequence[ST]:
"""Ensure that selectors are in a sequence."""
if not isinstance(v, Sequence):
v = [v]
Expand Down Expand Up @@ -920,7 +923,7 @@ def from_selection(
if isinstance(selection, TextQuoteSelector):
selection = [selection]
elif isinstance(selection, TextPositionSelector):
return TextPositionSet(positions=selection)
return TextPositionSet(positions=[selection])
if isinstance(selection, bool):
return self.from_bool(selection)
return self.from_selection_sequence(selection)
Expand Down

0 comments on commit 15b846f

Please sign in to comment.