Skip to content

Commit

Permalink
refactor: tidy 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 ba0149a commit 708f79d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion plugin/rules/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any, Pattern, TypeVar, final

from more_itertools import first_true
from typing_extensions import Self

from ..cache import clearable_lru_cache
from ..constants import PLUGIN_NAME, ST_PLATFORM
Expand Down Expand Up @@ -62,7 +63,7 @@ def test(self, view_snapshot: ViewSnapshot) -> bool:
return not result if self.inverted else result

@classmethod
def make(cls, constraint_rule: ST_ConstraintRule) -> ConstraintRule:
def make(cls, constraint_rule: ST_ConstraintRule) -> Self:
"""Build this object with the `constraint_rule`."""
obj = cls()

Expand Down
3 changes: 2 additions & 1 deletion plugin/rules/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Union, final

from more_itertools import first_true
from typing_extensions import Self

from ..cache import clearable_lru_cache
from ..snapshot import ViewSnapshot
Expand Down Expand Up @@ -58,7 +59,7 @@ def test(self, view_snapshot: ViewSnapshot) -> bool:
return self.match.test(view_snapshot, self.rules)

@classmethod
def make(cls, match_rule: ST_MatchRule) -> MatchRule:
def make(cls, match_rule: ST_MatchRule) -> Self:
"""Build this object with the `match_rule`."""
obj = cls()

Expand Down
5 changes: 3 additions & 2 deletions plugin/rules/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sublime
from more_itertools import first_true
from typing_extensions import Self

from ..constants import VERSION
from ..snapshot import ViewSnapshot
Expand Down Expand Up @@ -52,7 +53,7 @@ def test(self, view_snapshot: ViewSnapshot, event: ListenerEvent | None = None)
return self.root_rule.test(view_snapshot)

@classmethod
def make(cls, syntax_rule: ST_SyntaxRule) -> SyntaxRule:
def make(cls, syntax_rule: ST_SyntaxRule) -> Self:
"""Build this object with the `syntax_rule`."""
obj = cls()

Expand Down Expand Up @@ -106,7 +107,7 @@ def test(self, view_snapshot: ViewSnapshot, event: ListenerEvent | None = None)
return first_true(self.rules, pred=lambda rule: rule.test(view_snapshot, event))

@classmethod
def make(cls, syntax_rules: Iterable[ST_SyntaxRule]) -> SyntaxRuleCollection:
def make(cls, syntax_rules: Iterable[ST_SyntaxRule]) -> Self:
"""Build this object with the `syntax_rules`."""
obj = cls()
obj.rules = tuple(map(SyntaxRule.make, syntax_rules))
Expand Down
3 changes: 2 additions & 1 deletion plugin/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

import sublime
from typing_extensions import Self

from .encodings import from_sublime as encoding_from_sublime
from .settings import get_merged_plugin_setting
Expand Down Expand Up @@ -77,7 +78,7 @@ def valid_view(self) -> sublime.View | None:
return self.view if self.view.is_valid() else None

@classmethod
def from_view(cls, view: sublime.View) -> ViewSnapshot:
def from_view(cls, view: sublime.View) -> Self:
"""Create a `ViewSnapshot` object from a `sublime.View` object."""
window = view.window() or sublime.active_window()

Expand Down
3 changes: 2 additions & 1 deletion plugin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any, Generic, TypedDict, TypeVar, Union, overload

import sublime
from typing_extensions import Self

SyntaxLike = Union[str, sublime.Syntax]
WindowId = int
Expand Down Expand Up @@ -73,7 +74,7 @@ class ListenerEvent(StrEnum):
UNTRANSIENTIZE = "untransientize"

@classmethod
def from_value(cls, value: Any) -> ListenerEvent | None:
def from_value(cls, value: Any) -> Self | None:
try:
return cls(value)
except ValueError:
Expand Down

0 comments on commit 708f79d

Please sign in to comment.