mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-12 03:49:59 -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:
+14
-10
@@ -1,17 +1,18 @@
|
||||
import json as j
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
from typing import Any
|
||||
|
||||
socket_base = f"{os.getenv('XDG_RUNTIME_DIR')}/hypr/{os.getenv('HYPRLAND_INSTANCE_SIGNATURE')}"
|
||||
socket_path = f"{socket_base}/.socket.sock"
|
||||
socket2_path = f"{socket_base}/.socket2.sock"
|
||||
|
||||
|
||||
def message(msg: str, json: bool = True) -> str | dict[str, any]:
|
||||
def message(msg: str, is_json: bool = True) -> str | dict[str, Any]:
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(socket_path)
|
||||
|
||||
if json:
|
||||
if is_json:
|
||||
msg = f"j/{msg}"
|
||||
sock.send(msg.encode())
|
||||
|
||||
@@ -22,14 +23,17 @@ def message(msg: str, json: bool = True) -> str | dict[str, any]:
|
||||
break
|
||||
resp += new_resp.decode()
|
||||
|
||||
return j.loads(resp) if json else resp
|
||||
return json.loads(resp) if is_json else resp
|
||||
|
||||
|
||||
def dispatch(dispatcher: str, *args: list[any]) -> bool:
|
||||
return message(f"dispatch {dispatcher} {' '.join(map(str, args))}".rstrip(), json=False) == "ok"
|
||||
def dispatch(dispatcher: str, *args: str) -> bool:
|
||||
return message(f"dispatch {dispatcher} {' '.join(map(str, args))}".rstrip(), is_json=False) == "ok"
|
||||
|
||||
|
||||
def batch(*msgs: list[str], json: bool = False) -> str | dict[str, any]:
|
||||
if json:
|
||||
msgs = (f"j/{m.strip()}" for m in msgs)
|
||||
return message(f"[[BATCH]]{';'.join(msgs)}", json=False)
|
||||
def batch(*msgs: str, is_json: bool = False) -> str | dict[str, Any]:
|
||||
formatted_msgs = msgs
|
||||
|
||||
if is_json:
|
||||
formatted_msgs = [f"j/{m.strip()}" for m in msgs]
|
||||
|
||||
return message(f"[[BATCH]]{';'.join(formatted_msgs)}", is_json=False)
|
||||
|
||||
Reference in New Issue
Block a user