diff --git a/stubs/textblob/@tests/stubtest_allowlist.txt b/stubs/textblob/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..85b7f759b5a2 --- /dev/null +++ b/stubs/textblob/@tests/stubtest_allowlist.txt @@ -0,0 +1,20 @@ +textblob._text +textblob.classifiers +textblob.decorators +textblob.download_corpora +textblob.en +textblob.en.inflect +textblob.en.np_extractors +textblob.en.parsers +textblob.en.sentiments +textblob.en.taggers +textblob.formats +textblob.inflect +textblob.mixins +textblob.np_extractors +textblob.parsers +textblob.sentiments +textblob.taggers +textblob.tokenizers +textblob.utils +textblob.wordnet diff --git a/stubs/textblob/METADATA.toml b/stubs/textblob/METADATA.toml new file mode 100644 index 000000000000..65de9b55f396 --- /dev/null +++ b/stubs/textblob/METADATA.toml @@ -0,0 +1,3 @@ +version = "0.20.*" +upstream-repository = "https://github.com/sloria/TextBlob" +partial-stub = true diff --git a/stubs/textblob/textblob/__init__.pyi b/stubs/textblob/textblob/__init__.pyi new file mode 100644 index 000000000000..65d9068394eb --- /dev/null +++ b/stubs/textblob/textblob/__init__.pyi @@ -0,0 +1,3 @@ +from .blob import Blobber as Blobber, Sentence as Sentence, TextBlob as TextBlob, Word as Word, WordList as WordList + +__all__ = ["TextBlob", "Word", "Sentence", "Blobber", "WordList"] diff --git a/stubs/textblob/textblob/base.pyi b/stubs/textblob/textblob/base.pyi new file mode 100644 index 000000000000..bebdf6e7d596 --- /dev/null +++ b/stubs/textblob/textblob/base.pyi @@ -0,0 +1,24 @@ +from _typeshed import Incomplete +from abc import ABCMeta, abstractmethod +from typing import Any, AnyStr + +class BaseTagger(metaclass=ABCMeta): + @abstractmethod + def tag(self, text: str, tokenize: bool = True) -> list[tuple[str, str]]: ... + +class BaseNPExtractor(metaclass=ABCMeta): + @abstractmethod + def extract(self, text: str) -> list[str]: ... + +class BaseTokenizer(metaclass=ABCMeta): + @abstractmethod + def tokenize(self, text: str) -> list[str]: ... + def itokenize(self, text: str, *args: Incomplete, **kwargs: Incomplete) -> Incomplete: ... + +class BaseSentimentAnalyzer(metaclass=ABCMeta): + def train(self) -> None: ... + def analyze(self, text: str) -> Any: ... + +class BaseParser(metaclass=ABCMeta): + @abstractmethod + def parse(self, text: AnyStr) -> Incomplete: ... diff --git a/stubs/textblob/textblob/blob.pyi b/stubs/textblob/textblob/blob.pyi new file mode 100644 index 000000000000..6fc3e1b8012e --- /dev/null +++ b/stubs/textblob/textblob/blob.pyi @@ -0,0 +1,124 @@ +from _typeshed import Incomplete +from collections.abc import Iterable +from typing_extensions import Self + +from .base import BaseNPExtractor, BaseParser, BaseSentimentAnalyzer, BaseTagger, BaseTokenizer + +class Word(str): + pos_tag: str | None + def __new__(cls, string: str, pos_tag: str | None = None) -> Self: ... + def __init__(self, string: str, pos_tag: str | None = None) -> None: ... + def singularize(self) -> Word: ... + def pluralize(self) -> Word: ... + def spellcheck(self) -> list[tuple[str, float]]: ... + def correct(self) -> Word: ... + @property + def lemma(self) -> str: ... + def lemmatize(self, pos: str | None = None) -> str: ... + def stem(self, stemmer: Incomplete = ...) -> str: ... + @property + def synsets(self) -> list[Incomplete]: ... + @property + def definitions(self) -> list[str]: ... + def get_synsets(self, pos: str | None = None) -> list[Incomplete]: ... + def define(self, pos: str | None = None) -> list[str]: ... + +class WordList(list[Word]): + def __init__(self, collection: Iterable[str]) -> None: ... + def count(self, strg: str, case_sensitive: bool = False, *args: Incomplete, **kwargs: Incomplete) -> int: ... + def append(self, obj: str) -> None: ... + def extend(self, iterable: Iterable[str]) -> None: ... + def upper(self) -> WordList: ... + def lower(self) -> WordList: ... + def singularize(self) -> WordList: ... + def pluralize(self) -> WordList: ... + def lemmatize(self) -> WordList: ... + def stem(self, *args: Incomplete, **kwargs: Incomplete) -> WordList: ... + +class BaseBlob: + raw: str + string: str + stripped: str + np_extractor: BaseNPExtractor + pos_tagger: BaseTagger + tokenizer: BaseTokenizer + analyzer: BaseSentimentAnalyzer + parser: BaseParser + classifier: Incomplete + def __init__( + self, + text: str, + tokenizer: BaseTokenizer | None = None, + pos_tagger: BaseTagger | None = None, + np_extractor: BaseNPExtractor | None = None, + analyzer: BaseSentimentAnalyzer | None = None, + parser: BaseParser | None = None, + classifier: Incomplete = None, + clean_html: bool = False, + ) -> None: ... + @property + def words(self) -> WordList: ... + @property + def tokens(self) -> WordList: ... + def tokenize(self, tokenizer: BaseTokenizer | None = None) -> WordList: ... + def parse(self, parser: BaseParser | None = None) -> Incomplete: ... + def classify(self) -> Incomplete: ... + @property + def sentiment(self) -> Incomplete: ... + @property + def sentiment_assessments(self) -> Incomplete: ... + @property + def polarity(self) -> float: ... + @property + def subjectivity(self) -> float: ... + @property + def noun_phrases(self) -> WordList: ... + @property + def pos_tags(self) -> list[tuple[Word, str]]: ... + @property + def word_counts(self) -> dict[Word, int]: ... + @property + def np_counts(self) -> dict[str, int]: ... + def ngrams(self, n: int = 3) -> list[WordList]: ... + def correct(self) -> Self: ... + def split(self, sep: str | None = None, maxsplit: int = ...) -> WordList: ... + +class TextBlob(BaseBlob): + @property + def sentences(self) -> list[Sentence]: ... + @property + def raw_sentences(self) -> list[str]: ... + @property + def serialized(self) -> list[dict[str, Incomplete]]: ... + def to_json(self, *args: Incomplete, **kwargs: Incomplete) -> str: ... + @property + def json(self) -> str: ... + +class Sentence(BaseBlob): + start: int + start_index: int + end: int + end_index: int + def __init__( + self, sentence: str, start_index: int = 0, end_index: int | None = None, *args: Incomplete, **kwargs: Incomplete + ) -> None: ... + @property + def dict(self) -> dict[str, Incomplete]: ... + +class Blobber: + np_extractor: BaseNPExtractor + pos_tagger: BaseTagger + tokenizer: BaseTokenizer + analyzer: BaseSentimentAnalyzer + parser: BaseParser + classifier: Incomplete + def __init__( + self, + tokenizer: BaseTokenizer | None = None, + pos_tagger: BaseTagger | None = None, + np_extractor: BaseNPExtractor | None = None, + analyzer: BaseSentimentAnalyzer | None = None, + parser: BaseParser | None = None, + classifier: Incomplete = None, + ) -> None: ... + def __call__(self, text: str) -> TextBlob: ... diff --git a/stubs/textblob/textblob/exceptions.pyi b/stubs/textblob/textblob/exceptions.pyi new file mode 100644 index 000000000000..7b300f8de378 --- /dev/null +++ b/stubs/textblob/textblob/exceptions.pyi @@ -0,0 +1,6 @@ +class TextBlobError(Exception): ... +class MissingCorpusError(TextBlobError): ... +class DeprecationError(TextBlobError): ... +class TranslatorError(TextBlobError): ... +class NotTranslated(TranslatorError): ... +class FormatError(TextBlobError): ...