mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-08 00:09:29 -05:00
refactor: enforce stricter type hints (#91)
LSP was screaming at me so I decided to just address it to get it off my screen. + Fixed the type hints := Modified and added type hints for certain functions and variables in most of the files in the utils/ folder (and some in the subcommands/ folder) for clarity and so pyright's type checker wouldn't cry. :+ To resolve certain type issues, I had to add a bit more tiny additional code such as, additional checks if a variable is None, a tiny class in utils/material/generator.py to resolve the constructor usage mismatch between what the DynamicScheme accepts and what the code actually passes, and etc. - Renamed certain functions and variables for clarity and also for some to not collide with pre-existing definitions from well-known library imports. + PIL has reorganized their code a bit, so the code is made to reflect their new definitions. = Reorganized the single import statement for "colourfulness" in utils/wallpaper.py to be close to the top. (I think that's it) Side Effects?: Everything should work the same as no logic change was done whatsover (unless we consider the added if statements for type checking as a logic change). I've tested it, everything seems to be in urdir.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import random
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from caelestia.utils.notify import notify
|
||||
from caelestia.utils.paths import atomic_dump, scheme_data_dir, scheme_path
|
||||
@@ -14,19 +15,19 @@ class Scheme:
|
||||
_colours: dict[str, str]
|
||||
notify: bool
|
||||
|
||||
def __init__(self, json: dict[str, any] | None) -> None:
|
||||
if json is None:
|
||||
def __init__(self, scheme_json: dict[str, Any] | None) -> None:
|
||||
if scheme_json is None:
|
||||
self._name = "catppuccin"
|
||||
self._flavour = "mocha"
|
||||
self._mode = "dark"
|
||||
self._variant = "tonalspot"
|
||||
self._colours = read_colours_from_file(self.get_colours_path())
|
||||
else:
|
||||
self._name = json["name"]
|
||||
self._flavour = json["flavour"]
|
||||
self._mode = json["mode"]
|
||||
self._variant = json["variant"]
|
||||
self._colours = json["colours"]
|
||||
self._name = scheme_json["name"]
|
||||
self._flavour = scheme_json["flavour"]
|
||||
self._mode = scheme_json["mode"]
|
||||
self._variant = scheme_json["variant"]
|
||||
self._colours = scheme_json["colours"]
|
||||
self.notify = False
|
||||
|
||||
@property
|
||||
@@ -196,7 +197,7 @@ scheme_variants = [
|
||||
"content",
|
||||
]
|
||||
|
||||
scheme: Scheme = None
|
||||
scheme: Scheme | None = None
|
||||
|
||||
|
||||
def read_colours_from_file(path: Path) -> dict[str, str]:
|
||||
@@ -225,7 +226,7 @@ def get_scheme_names() -> list[str]:
|
||||
return [*(f.name for f in scheme_data_dir.iterdir() if f.is_dir()), "dynamic"]
|
||||
|
||||
|
||||
def get_scheme_flavours(name: str = None) -> list[str]:
|
||||
def get_scheme_flavours(name: str | None = None) -> list[str]:
|
||||
if name is None:
|
||||
name = get_scheme().name
|
||||
|
||||
@@ -234,11 +235,11 @@ def get_scheme_flavours(name: str = None) -> list[str]:
|
||||
)
|
||||
|
||||
|
||||
def get_scheme_modes(name: str = None, flavour: str = None) -> list[str]:
|
||||
if name is None:
|
||||
def get_scheme_modes(name: str | None = None, flavour: str | None = None) -> list[str]:
|
||||
if name is None or flavour is None:
|
||||
scheme = get_scheme()
|
||||
name = scheme.name
|
||||
flavour = scheme.flavour
|
||||
name = name or scheme.name
|
||||
flavour = flavour or scheme.flavour
|
||||
|
||||
if name == "dynamic":
|
||||
return ["light", "dark"]
|
||||
|
||||
Reference in New Issue
Block a user