Skip to content

Commit

Permalink
Enchant: Spell checking library for Enchant WIP
Browse files Browse the repository at this point in the history
<https://github.com/pyenchant/pyenchant>
<http://pyenchant.github.io/pyenchant/api/index.html>

- [ ] API-2 accepts Union[Text, bytes], see <python/typing#208>
- [ ] API-3 provides new functions and is Pyhton-3-only
  • Loading branch information
pmhahn committed Jul 21, 2020
1 parent e44ac21 commit 526c637
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 0 deletions.
71 changes: 71 additions & 0 deletions third_party/2and3/enchant/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from enchant.errors import *
from enchant.pypwl import PyPWL as PyPWL
from enchant.utils import EnchantStr as EnchantStr, UTF16EnchantStr as UTF16EnchantStr, get_default_language as get_default_language
from typing import Any, List, Tuple

class warnings:
def warn(self, *args: Any, **kwds: Any) -> None: ...

class ProviderDesc:
name: str = ...
desc: str = ...
file: str = ...
def __init__(self, name: str, desc: str, file: str) -> None: ...
def __eq__(self, pd: Any) -> bool: ...
def __hash__(self) -> int: ...

class _EnchantObject:
def __init__(self) -> None: ...

class Broker(_EnchantObject):
def __init__(self) -> None: ...
def __del__(self) -> None: ...
def request_dict(self, tag: str = ...) -> Dict: ...
def request_pwl_dict(self, pwl: str) -> Dict: ...
def dict_exists(self, tag: str) -> bool: ...
def set_ordering(self, tag: str, ordering: str) -> None: ...
def describe(self) -> List[ProviderDesc]: ...
def list_dicts(self) -> List[Tuple[str, ProviderDesc]]: ...
def list_languages(self) -> List[str]: ...
def get_param(self, name: str) -> Any: ...
def set_param(self, name: str, value: Any) -> None: ...

class Dict(_EnchantObject):
provider: ProviderDesc = ...
tag: str = ...
def __init__(self, tag: str = ..., broker: Broker = ...) -> None: ...
def __del__(self) -> None: ...
def check(self, word: str) -> bool: ...
def suggest(self, word: str) -> List[str]: ...
def add(self, word: str) -> None: ...
def remove(self, word: str) -> None: ...
def add_to_pwl(self, word: str) -> None: ...
def add_to_session(self, word: str) -> None: ...
def remove_from_session(self, word: str) -> None: ...
def is_added(self, word: str) -> bool: ...
def is_removed(self, word: str) -> bool: ...
def store_replacement(self, mis: str, cor: str) -> None: ...

class DictWithPWL(Dict):
pwl: Dict = ...
pel: Dict = ...
def __init__(self, tag: str, pwl: str = ..., pel: str = ..., broker: Broker = ...) -> None: ...
def check(self, word: str) -> bool: ...
def suggest(self, word: str) -> List[str]: ...
def add(self, word: str) -> None: ...
def remove(self, word: str) -> None: ...
def add_to_pwl(self, word: str) -> None: ...
def is_added(self, word: str) -> bool: ...
def is_removed(self, word: str) -> bool: ...

def request_dict(self, tag: str = ...) -> Dict: ...
def request_pwl_dict(self, pwl: str) -> Dict: ...
def dict_exists(tag: str) -> bool: ...
def list_dicts() -> List[Tuple[str, ProviderDesc]]: ...
def list_languages() -> List[str]: ...
def get_param(name: str) -> Any: ...
def set_param(name: str, value: Any) -> None: ...

def get_enchant_version() -> str: ...
def set_prefix_dir(path: str) -> None: ...
def get_user_config_dir() -> str: ...
22 changes: 22 additions & 0 deletions third_party/2and3/enchant/checker/CmdLineChecker.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from enchant.checker import SpellChecker
from typing import Dict, Optional

colors: Dict[str, str]

def color(string: str, color: str = ..., prefix: str = ...): ...
def success(string: str): ...
def error(string: str): ...
def warning(string: str): ...
def info(string: str): ...

class CmdLineChecker:
def __init__(self) -> None: ...
def set_checker(self, chkr: SpellChecker) -> None: ...
def get_checker(self, chkr: SpellChecker) -> SpellChecker: ...
# error: Any = ...
def run(self) -> None: ...
def print_error(self) -> None: ...
def print_suggestions(self) -> None: ...
def print_help(self) -> None: ...
def read_command(self) -> bool: ...
def run_on_file(self, infile: str, outfile: str = ..., enc: str = ...) -> None: ...
17 changes: 17 additions & 0 deletions third_party/2and3/enchant/checker/GtkSpellCheckerDialog.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import gtk
from enchant.checker import SpellChecker
from typing import Any

COLUMN_SUGGESTION: int

# def create_list_view(col_label: Any): ...

class GtkSpellCheckerDialog(gtk.Window):
# errors: Any = ...
# error_text: Any = ...
# replace_text: Any = ...
# suggestion_list_view: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def setSpellChecker(self, checker: SpellChecker) -> None: ...
def getSpellChecker(self, checker: SpellChecker): ...
def updateUI(self) -> None: ...
29 changes: 29 additions & 0 deletions third_party/2and3/enchant/checker/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from enchant.errors import *
from enchant.tokenize import get_tokenizer as get_tokenizer, tokenize, Chunker, Filter
from enchant.utils import get_default_language as get_default_language
from enchant import Dict
from typing import Iterator, List, Optional, Union, Type

class SpellChecker:
lang: str = ...
dict: Dict = ...
word: Optional[str] = ...
wordpos: Optional[int] = ...
def __init__(self, lang: Union[Dict, str] = ..., text: str = ..., tokenize: Union[Type[tokenize], Filter] = ..., chunkers: List[Chunker] = ..., filters: List[Filter] = ...) -> None: ...
def __iter__(self) -> Iterator[SpellChecker]: ...
def set_text(self, text: str) -> None: ...
def get_text(self) -> str: ...
def wants_unicode(self) -> bool: ...
def coerce_string(self, text: str, enc: str = ...) -> str: ...
def __next__(self) -> SpellChecker: ...
def next(self) -> SpellChecker: ...
def replace(self, repl: str) -> None: ...
def replace_always(self, word: str, repl: str = ...) -> None: ...
def ignore_always(self, word: str = ...) -> None: ...
def add_to_personal(self, word: str = ...) -> None: ...
def add(self, word: str = ...) -> None: ...
def suggest(self, word: str = ...) -> List[str]: ...
def check(self, word: str) -> bool: ...
def set_offset(self, off: int, whence: int = ...) -> None: ...
def leading_context(self, chars: int) -> str: ...
def trailing_context(self, chars: int) -> str: ...
24 changes: 24 additions & 0 deletions third_party/2and3/enchant/checker/wxSpellCheckerDialog.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import wx
from enchant.checker import SpellChecker
from typing import Any, Optional

class wxSpellCheckerDialog(wx.Dialog):
# sz: Any = ...
# error_text: Any = ...
# replace_text: Any = ...
# replace_list: Any = ...
def __init__(self, parent: Optional[Any] = ..., id: int = ..., title: str = ...) -> None: ...
# buttons: Any = ...
def InitLayout(self) -> None: ...
def Advance(self) -> bool: ...
def EnableButtons(self, state: bool = ...) -> None: ...
def GetRepl(self) -> str: ...
def OnAdd(self, evt: Any) -> None: ...
def OnDone(self, evt: Any) -> None: ...
def OnIgnore(self, evt: Any) -> None: ...
def OnIgnoreAll(self, evt: Any) -> None: ...
def OnReplace(self, evt: Any) -> None: ...
def OnReplaceAll(self, evt: Any) -> None: ...
def OnReplSelect(self, evt: Any) -> None: ...
def GetSpellChecker(self) -> SpellChecker: ...
def SetSpellChecker(self, chkr: SpellChecker) -> bool: ...
4 changes: 4 additions & 0 deletions third_party/2and3/enchant/errors.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Error(Exception): ...
class DictNotFoundError(Error): ...
class TokenizerNotFoundError(Error): ...
class DefaultLanguageNotFoundError(Error): ...
25 changes: 25 additions & 0 deletions third_party/2and3/enchant/pypwl.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Any, Iterable, Iterator, List, Optional

class Trie:
def __init__(self, words: Iterable[str] = ...) -> None: ...
def insert(self, word: str) -> None: ...
def remove(self, word: str) -> None: ...
def search(self, word: str, nerrs: int = ...) -> List[str]: ...
def __getitem__(self, key: str) -> Trie: ...
def __setitem__(self, key: str, val: Trie) -> None: ...
def __iter__(self) -> Iterator[str]: ...

class PyPWL:
provider: None = ...
pwl: Optional[str] = ...
tag: str = ...
def __init__(self, pwl: str = ...) -> None: ...
def check(self, word: str) -> bool: ...
def suggest(self, word: str) -> List[str]: ...
def add(self, word: str) -> None: ...
def add_to_pwl(self, word: str) -> None: ...
def remove(self, word: str) -> None: ...
def add_to_session(self, word: str) -> None: ...
def store_replacement(self, mis: str, cor: str) -> None: ...
def is_added(self, word: str) -> bool: ...
def is_removed(self, word: str) -> bool: ...
49 changes: 49 additions & 0 deletions third_party/2and3/enchant/tokenize/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# from enchant.errors import *
from typing import Any, Callable, Iterable, Iterator, Optional, Tuple, Type, Union
from typing_extensions import Protocol
Token = Tuple[str, int]

# Error = TokenizerNotFoundError

class tokenize(Protocol):
def __init__(self, text: str) -> None: ...
def __next__(self) -> Token: ...
def next(self) -> Token: ...
def __iter__(self) -> Iterator[Token]: ...
def set_offset(self, offset: int, replaced: bool = ...) -> None: ...
offset: int = ...

class empty_tokenize(tokenize):
def __init__(self) -> None: ...

class unit_tokenize(tokenize):
def __init__(self, text: str) -> None: ...

class basic_tokenize(tokenize):
strip_from_start: str = ...
strip_from_end: str = ...

class Chunker(tokenize): ...

_Filter = Union[Type[tokenize], Filter]

class Filter(tokenize):
def __init__(self, tokenizer: _Filter) -> None: ...
def __call__(self, *args: Any, **kwds: Any) -> tokenize: ...
def _skip(self, word: str) -> bool: ...
def _split(self, word: str) -> tokenize: ...
class _TokenFilter(tokenize):
def __init__(self, tokenizer: _Filter, skip: Callable[[str], bool], split: Callable[[str], tokenize]) -> None: ...

def wrap_tokenizer(tk1: _Filter, tk2: _Filter) -> Filter: ...

class URLFilter(Filter): ...
class WikiWordFilter(Filter): ...
class EmailFilter(Filter): ...
class MentionFilter(Filter): ...
class HashtagFilter(Filter): ...

class HTMLChunker(Chunker):
def next(self) -> Token: ...

def get_tokenizer(tag: str = ..., chunkers: Iterable[Chunker] = ..., filters: Iterable[Filter] = ...) -> tokenize: ...
6 changes: 6 additions & 0 deletions third_party/2and3/enchant/tokenize/en.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import enchant.tokenize
from typing import Container

class tokenize(enchant.tokenize.tokenize):
def __init__(self, text: str, valid_chars: Container[str] = ...) -> None: ...
def next(self) -> enchant.tokenize.Token: ...
22 changes: 22 additions & 0 deletions third_party/2and3/enchant/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from enchant.errors import *
from typing import Any, Callable, IO, Iterable, List, Optional, Text, Tuple

def raw_unicode(raw: bytes) -> Text: ...
def raw_bytes(raw: Any) -> bytes: ...

class EnchantStr(str):
def __new__(cls, value: Any): ...
def encode(self) -> bytes: ... # type: ignore
def decode(self, value: Any) -> Text: ... # type: ignore

class UTF16EnchantStr(EnchantStr):
REPLACEMENT_CHAR: str = ...
def encode(self) -> bytes: ... # type: ignore

def printf(values: Iterable[Any], sep: str = ..., end: str = ..., file: IO[str] = ...) -> None: ...

def levenshtein(s1: str, s2: str) -> int: ...
def trim_suggestions(word: str, suggs: Iterable[str], maxlen: int, calcdist: Callable[[str, str], int] = ...) -> List[str]: ...
def get_default_language(default: str = ...) -> str: ...
def get_resource_filename(resname: str) -> str: ...
def win32_data_files() -> List[Tuple[str, List[str]]]: ...

0 comments on commit 526c637

Please sign in to comment.