Skip to content

Commit

Permalink
Add typing information
Browse files Browse the repository at this point in the history
  • Loading branch information
cvzi committed Jun 6, 2023
1 parent 00a74b4 commit df32d07
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 17 deletions.
29 changes: 18 additions & 11 deletions emoji/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@ from .core import (
is_emoji as is_emoji,
replace_emoji as replace_emoji,
version as version,
analyze as analyze,
config as config,
)
from .tokenizer import (
Token as Token,
EmojiMatch as EmojiMatch,
EmojiMatchZWJ as EmojiMatchZWJ,
EmojiMatchZWJNonRGI as EmojiMatchZWJNonRGI,
)


from .unicode_codes import EMOJI_DATA, LANGUAGES, STATUS

__all__ = [
"emojize",
"demojize",
"emoji_count",
"emoji_list",
"distinct_emoji_list",
"replace_emoji",
"version",
"is_emoji",
"EMOJI_DATA",
"STATUS",
"LANGUAGES",
# emoji.core
'emojize', 'demojize', 'analyze', 'config',
'emoji_list', 'distinct_emoji_list', 'emoji_count',
'replace_emoji', 'is_emoji', 'version',
'Token', 'EmojiMatch', 'EmojiMatchZWJ', 'EmojiMatchZWJNonRGI',
# emoji.unicode_codes
'EMOJI_DATA', 'STATUS', 'LANGUAGES',
]

__version__: str
__author__: str
__email__: str
Expand Down
24 changes: 18 additions & 6 deletions emoji/core.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from collections.abc import Callable
from typing_extensions import Literal, TypedDict
from typing import Iterator
from .tokenizer import Token

_DEFAULT_DELIMITER: str

class _EmojiLisReturn(TypedDict):
emoji: str
location: int
class config:
demojize_keep_zwj: bool
replace_emoji_keep_zwj: bool


class _EmojiListReturn(TypedDict):
emoji: str
match_start: int
match_end: int


def emojize(
string: str,
delimiters: tuple[str, str] = ...,
Expand All @@ -20,16 +23,25 @@ def emojize(
version: float | None = ...,
handle_version: str | Callable[[str, dict[str, str]], str] | None = ...,
) -> str: ...


def demojize(
string: str,
delimiters: tuple[str, str] = ...,
language: str = ...,
version: float | None = ...,
handle_version: str | Callable[[str, dict[str, str]], str] | None = ...,
) -> str: ...
def replace_emoji(string: str, replace: str | Callable[[str, dict[str, str]], str] = ..., version: float = ...) -> str: ...


def analyze(string: str, non_emoji: bool,
join_emoji: bool) -> Iterator[Token]: ...
def replace_emoji(string: str, replace: str | Callable[[
str, dict[str, str]], str] = ..., version: float = ...) -> str: ...


def emoji_list(string: str) -> list[_EmojiListReturn]: ...
def distinct_emoji_list(string: str) -> list[str]: ...
def emoji_count(string: str, unique: bool = ...) -> int: ...
def version(string: str) -> float: ...
def is_emoji(string: str) -> bool: ...
def is_emoji(string: str) -> bool: ...
47 changes: 47 additions & 0 deletions emoji/tokenizer.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import NamedTuple, Union, Dict, Iterator, Any

_SearchTree = Dict[str, Union['_SearchTree', dict[str, dict[str, Any]]]]

_SEARCH_TREE: _SearchTree


class EmojiMatch:
emoji: str
start: int
end: int
data: dict[str, Any] | None
def __init__(self, emoji: str, start: int,
end: int, data: dict | None): ...

def data_copy(self) -> Dict[str, Any]: ...
def is_zwj(self) -> bool: ...
def split(self) -> EmojiMatchZWJ | EmojiMatch: ...
def __repr__(self) -> str: ...


class EmojiMatchZWJ(EmojiMatch):
def __init__(self, match: EmojiMatch): ...
def join(self) -> str: ...
def is_zwj(self) -> bool: ...
def split(self) -> EmojiMatchZWJ: ...
def __repr__(self) -> str: ...


class EmojiMatchZWJNonRGI(EmojiMatchZWJ):
def __init__(self, first_emoji_match: EmojiMatch,
second_emoji_match: EmojiMatch): ...


class Token(NamedTuple):
chars: str
value: str | EmojiMatch


def tokenize(string, keep_zwj: bool) -> Iterator[Token]: ...


def filter_tokens(matches: Iterator[Token], emoji_only: bool,
join_emoji: bool) -> Iterator[Token]: ...


def get_search_tree() -> _SearchTree: ...

0 comments on commit df32d07

Please sign in to comment.