Skip to content

Commit

Permalink
refactor: ticy codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed May 20, 2024
1 parent 1510ce6 commit 4bfe542
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions boot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


def reload_plugin() -> None:
import sys

Expand Down
6 changes: 4 additions & 2 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from .commands import * # noqa: F401, F403


def plugin_loaded() -> None:
pass
"""Executed when this plugin is loaded."""


def plugin_unloaded() -> None:
pass
"""Executed when this plugin is unloaded."""
2 changes: 2 additions & 0 deletions plugin/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from .select_emoji import SelectEmojiCommand

__all__ = (
Expand Down
11 changes: 6 additions & 5 deletions plugin/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any

import sublime
from typing_extensions import Self

from .constants import DB_FILE_CACHED, DB_FILE_IN_PACKAGE, DB_REVISION
from .data_types import StrEnum
Expand Down Expand Up @@ -85,7 +86,7 @@ def __str__(self) -> str:
)

@classmethod
def from_dict(cls, db: dict[str, Any]) -> Emoji:
def from_dict(cls, db: dict[str, Any]) -> Self:
return cls(
char=db["char"], # required
codes=db.get("codes") or cls.str_to_code_points(db["char"]),
Expand All @@ -95,7 +96,7 @@ def from_dict(cls, db: dict[str, Any]) -> Emoji:
)

@classmethod
def from_line(cls, line: str) -> Emoji | None:
def from_line(cls, line: str) -> Self | None:
if m := cls._re_line.fullmatch(line):
return cls(
char=m.group("char").strip(),
Expand Down Expand Up @@ -152,11 +153,11 @@ def __str__(self) -> str:
"""

@classmethod
def from_content(cls, content: str) -> EmojiDatabase:
def from_content(cls, content: str) -> Self:
return cls.from_lines(content.splitlines())

@classmethod
def from_dict(cls, db: dict[str, Any]) -> EmojiDatabase:
def from_dict(cls, db: dict[str, Any]) -> Self:
return cls(
db_revision=db.get("db_revision", DB_REVISION),
date=db.get("date", ""),
Expand All @@ -165,7 +166,7 @@ def from_dict(cls, db: dict[str, Any]) -> EmojiDatabase:
)

@classmethod
def from_lines(cls, lines: Iterable[str]) -> EmojiDatabase:
def from_lines(cls, lines: Iterable[str]) -> Self:
collection = cls(db_revision=DB_REVISION)
for line in lines:
if emoji := Emoji.from_line(line):
Expand Down

0 comments on commit 4bfe542

Please sign in to comment.