From 4bfe5428abecfe035ab9cb8ef5483fee75a28cd6 Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Tue, 21 May 2024 03:27:30 +0800 Subject: [PATCH] refactor: ticy codes Signed-off-by: Jack Cherng --- boot.py | 3 +++ plugin/__init__.py | 6 ++++-- plugin/commands/__init__.py | 2 ++ plugin/emoji.py | 11 ++++++----- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/boot.py b/boot.py index 98fbbdd..8d5b832 100644 --- a/boot.py +++ b/boot.py @@ -1,3 +1,6 @@ +from __future__ import annotations + + def reload_plugin() -> None: import sys diff --git a/plugin/__init__.py b/plugin/__init__.py index 046e325..bce609d 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -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.""" diff --git a/plugin/commands/__init__.py b/plugin/commands/__init__.py index fd7ee3f..d5cb2a3 100644 --- a/plugin/commands/__init__.py +++ b/plugin/commands/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from .select_emoji import SelectEmojiCommand __all__ = ( diff --git a/plugin/emoji.py b/plugin/emoji.py index 8704c2a..e18985b 100644 --- a/plugin/emoji.py +++ b/plugin/emoji.py @@ -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 @@ -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"]), @@ -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(), @@ -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", ""), @@ -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):