Skip to content

Commit e8ef4a4

Browse files
ldorigoadrianeboyd
andauthored
Add the right return type for Language.pipe and an overload for the as_tuples case (#8441)
* Add the right return type for Language.pipe and an overload for the as_tuples version * Reformat, tidy up Co-authored-by: Adriane Boyd <[email protected]>
1 parent b9f5911 commit e8ef4a4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

spacy/language.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Optional, Any, Dict, Callable, Iterable, Union, List, Pattern
1+
from typing import Iterator, Optional, Any, Dict, Callable, Iterable, TypeVar
2+
from typing import Union, List, Pattern, overload
23
from typing import Tuple
34
from dataclasses import dataclass
45
import random
@@ -1431,6 +1432,21 @@ def use_params(self, params: Optional[dict]):
14311432
except StopIteration:
14321433
pass
14331434

1435+
_AnyContext = TypeVar("_AnyContext")
1436+
1437+
@overload
1438+
def pipe(
1439+
self,
1440+
texts: Iterable[Tuple[str, _AnyContext]],
1441+
*,
1442+
as_tuples: bool = ...,
1443+
batch_size: Optional[int] = ...,
1444+
disable: Iterable[str] = ...,
1445+
component_cfg: Optional[Dict[str, Dict[str, Any]]] = ...,
1446+
n_process: int = ...,
1447+
) -> Iterator[Tuple[Doc, _AnyContext]]:
1448+
...
1449+
14341450
def pipe(
14351451
self,
14361452
texts: Iterable[str],
@@ -1440,7 +1456,7 @@ def pipe(
14401456
disable: Iterable[str] = SimpleFrozenList(),
14411457
component_cfg: Optional[Dict[str, Dict[str, Any]]] = None,
14421458
n_process: int = 1,
1443-
):
1459+
) -> Iterator[Doc]:
14441460
"""Process texts as a stream, and yield `Doc` objects in order.
14451461
14461462
texts (Iterable[str]): A sequence of texts to process.

0 commit comments

Comments
 (0)