From cdef95117173b9b1afed790f47836456e02c7125 Mon Sep 17 00:00:00 2001 From: Moosems <95927277+Moosems@users.noreply.github.com> Date: Sun, 16 Jun 2024 19:46:34 -0600 Subject: [PATCH] Use `beartype.claw.beartype_this_package()` instead of `@beartype.beartype` (#22) * Use beartype_this_package * Format --- salve_ipc/__init__.py | 4 ++++ salve_ipc/ipc.py | 10 ---------- salve_ipc/server.py | 5 ----- salve_ipc/server_functions.py | 10 ---------- 4 files changed, 4 insertions(+), 25 deletions(-) diff --git a/salve_ipc/__init__.py b/salve_ipc/__init__.py index 6df9924..8c37e40 100644 --- a/salve_ipc/__init__.py +++ b/salve_ipc/__init__.py @@ -1,3 +1,5 @@ +from beartype.claw import beartype_this_package + from .ipc import IPC # noqa: F401 from .misc import COMMANDS, Response # noqa: F401 from .server_functions import ( # noqa: F401 @@ -5,3 +7,5 @@ generic_tokens, is_unicode_letter, ) + +beartype_this_package() diff --git a/salve_ipc/ipc.py b/salve_ipc/ipc.py index d162baa..b8cc0ac 100644 --- a/salve_ipc/ipc.py +++ b/salve_ipc/ipc.py @@ -4,8 +4,6 @@ from pathlib import Path from random import randint -from beartype import beartype - from .misc import COMMANDS, Notification, Request, Response from .server import Server @@ -19,7 +17,6 @@ class IPC: - IPC.kill_IPC() """ - @beartype def __init__(self, id_max: int = 15_000) -> None: self.all_ids: list[int] = [] self.id_max = id_max @@ -55,7 +52,6 @@ def create_server(self) -> None: for filename, data in files_copy.items(): self.update_file(filename, data) - @beartype def create_message(self, type: str, **kwargs) -> None: """Creates a Message based on the args and kwawrgs provided. Highly flexible. - internal API""" id = randint(1, self.id_max) # 0 is reserved for the empty case @@ -95,7 +91,6 @@ def create_message(self, type: str, **kwargs) -> None: } self.requests_queue.put(notification) - @beartype def request( self, command: str, @@ -130,7 +125,6 @@ def request( definition_starters=definition_starters, ) - @beartype def cancel_request(self, command: str): """Cancels a request of type command - external API""" if command not in COMMANDS: @@ -141,7 +135,6 @@ def cancel_request(self, command: str): self.current_ids[command] = 0 - @beartype def parse_response(self, res: Response) -> None: """Parses main_server output line and discards useless responses - internal API""" id = res["id"] @@ -162,7 +155,6 @@ def check_responses(self) -> None: while not self.response_queue.empty(): self.parse_response(self.response_queue.get()) - @beartype def get_response(self, command: str) -> Response | None: """Runs IPC.check_responses() and returns the current response of type command if it has been returned - external API""" if command not in COMMANDS: @@ -176,7 +168,6 @@ def get_response(self, command: str) -> Response | None: self.newest_responses[command] = None return response - @beartype def update_file(self, filename: str, current_state: str) -> None: """Updates files in the system - external API""" @@ -186,7 +177,6 @@ def update_file(self, filename: str, current_state: str) -> None: "notification", filename=filename, contents=current_state ) - @beartype def remove_file(self, filename: str) -> None: """Removes a file from the main_server - external API""" if filename not in list(self.files.keys()): diff --git a/salve_ipc/server.py b/salve_ipc/server.py index 3593ed5..f7506c9 100644 --- a/salve_ipc/server.py +++ b/salve_ipc/server.py @@ -2,7 +2,6 @@ from multiprocessing.queues import Queue as GenericClassQueue from time import sleep -from beartype import beartype from pyeditorconfig import get_config from .misc import COMMANDS, Notification, Request, Response @@ -18,7 +17,6 @@ class Server: """Handles input from the user and returns output from special functions designed to make the job easy. Not an external API.""" - @beartype def __init__( self, server_end: Connection, @@ -41,7 +39,6 @@ def __init__( self.run_tasks() sleep(0.0025) - @beartype def simple_id_response(self, id: int, cancelled: bool = True) -> None: response: Response = { "id": id, @@ -50,7 +47,6 @@ def simple_id_response(self, id: int, cancelled: bool = True) -> None: } self.response_queue.put(response) - @beartype def parse_line(self, message: Request | Notification) -> None: id: int = message["id"] match message["type"]: @@ -83,7 +79,6 @@ def cancel_all_ids_except_newest(self) -> None: self.all_ids = [] - @beartype def handle_request(self, request: Request) -> None: command: str = request["command"] id: int = self.newest_ids[command] diff --git a/salve_ipc/server_functions.py b/salve_ipc/server_functions.py index eea0e88..a4d7de3 100644 --- a/salve_ipc/server_functions.py +++ b/salve_ipc/server_functions.py @@ -2,7 +2,6 @@ from re import Match, Pattern, compile from unicodedata import category -from beartype import beartype from pygments import lex from pygments.lexer import Lexer from pygments.lexers import get_lexer_by_name @@ -43,7 +42,6 @@ Token = tuple[tuple[int, int], int, str] -@beartype def get_new_token_type(old_token: str) -> str: """Turns pygments token types into a generic predefined Token""" new_type: str = generic_tokens[0] @@ -57,7 +55,6 @@ def get_new_token_type(old_token: str) -> str: url_regex: Pattern = compile(r"(ftp|http|https):\/\/[a-zA-Z0-9_-]") -@beartype def get_urls(lines: list[str], start_line: int = 1) -> list[Token]: start_pos: tuple[int, int] = (start_line, 0) url_toks: list[Token] = [] @@ -149,7 +146,6 @@ def get_urls(lines: list[str], start_line: int = 1) -> list[Token]: } -@beartype def find_hidden_chars(lines: list[str], start_line: int = 1) -> list[Token]: hidden_char_indexes: list[tuple[tuple[int, int], str]] = [ ((line_index + start_line, char_index), char) @@ -163,7 +159,6 @@ def find_hidden_chars(lines: list[str], start_line: int = 1) -> list[Token]: return tok_list -@beartype def get_highlights( full_text: str, language: str = "text", @@ -205,13 +200,11 @@ def get_highlights( return new_tokens -@beartype def is_unicode_letter(char: str) -> bool: """Returns a boolean value of whether a given unicode char is a letter or not (includes "_" for code completion reasons)""" return char == "_" or category(char).startswith("L") -@beartype def find_words(full_text: str) -> list[str]: """Returns a list of all words in a given piece of text""" words_list = [] @@ -237,7 +230,6 @@ def find_words(full_text: str) -> list[str]: return words_list -@beartype def find_autocompletions( full_text: str, expected_keywords: list[str], current_word: str ) -> list[str]: @@ -271,7 +263,6 @@ def find_autocompletions( return autocomplete_matches -@beartype def get_replacements( full_text: str, expected_keywords: list[str], replaceable_word: str ) -> list[str]: @@ -306,7 +297,6 @@ def get_replacements( return ranked_matches -@beartype def get_definition( full_text: str, definition_starters: list[tuple[str, str]],