From 2bbad4a5d1422f9b3c498775da2537a0fa67c1f1 Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Wed, 27 Nov 2024 20:52:07 +0100 Subject: [PATCH] make mypy happy --- tagstudio/src/core/query_lang/ast.py | 8 ++++---- tagstudio/src/core/query_lang/parser.py | 7 ++++--- tagstudio/src/core/query_lang/tokenizer.py | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tagstudio/src/core/query_lang/ast.py b/tagstudio/src/core/query_lang/ast.py index ae2aea81..a68feb91 100644 --- a/tagstudio/src/core/query_lang/ast.py +++ b/tagstudio/src/core/query_lang/ast.py @@ -24,16 +24,16 @@ class AST: return self.__str__() class ANDList(AST): - elements: list["ORList"] + elements: list[Union["ORList", "Constraint"]] - def __init__(self, elements: list["ORList"]) -> None: + def __init__(self, elements: list[Union["ORList", "Constraint"]]) -> None: super().__init__() self.elements = elements class ORList(AST): - terms: list[Union[ANDList, "Constraint"]] + terms: list[ANDList] - def __init__(self, terms: list[Union[ANDList, "Constraint"]]) -> None: + def __init__(self, terms: list[ANDList]) -> None: super().__init__() self.terms = terms diff --git a/tagstudio/src/core/query_lang/parser.py b/tagstudio/src/core/query_lang/parser.py index d185b841..c02f6b5d 100644 --- a/tagstudio/src/core/query_lang/parser.py +++ b/tagstudio/src/core/query_lang/parser.py @@ -89,16 +89,17 @@ class Parser: def __literal(self) -> str: if self.next_token.type in [TokenType.QLITERAL, TokenType.ULITERAL]: return self.__eat(self.next_token.type).value + raise self.__syntax_error() def __eat(self, type: TokenType) -> Token: if self.next_token.type != type: - self.__syntax_error(f"expected {type} found {self.next_token.type}") + raise self.__syntax_error(f"expected {type} found {self.next_token.type}") out = self.next_token self.next_token = self.tokenizer.get_next_token() return out - def __syntax_error(self, msg: str = "Syntax Error") -> None: - raise ParsingError(self.next_token.start, self.next_token.end, msg) + def __syntax_error(self, msg: str = "Syntax Error") -> ParsingError: + return ParsingError(self.next_token.start, self.next_token.end, msg) if __name__ == "__main__": #TODO remove print("") # noqa: T201 diff --git a/tagstudio/src/core/query_lang/tokenizer.py b/tagstudio/src/core/query_lang/tokenizer.py index fbc85e7d..c632d87c 100644 --- a/tagstudio/src/core/query_lang/tokenizer.py +++ b/tagstudio/src/core/query_lang/tokenizer.py @@ -1,4 +1,5 @@ from enum import Enum +from typing import Any from src.core.query_lang.ast import ConstraintType from src.core.query_lang.util import ParsingError @@ -19,19 +20,19 @@ class TokenType(Enum): class Token: type: TokenType - value: any + value: Any start: int end: int - def __init__(self, type: TokenType, value: any, start: int = None, end: int = None) -> None: + def __init__(self, type: TokenType, value: Any, start: int = None, end: int = None) -> None: self.type = type self.value = value self.start = start self.end = end @staticmethod - def from_type(type: TokenType, pos: int = None) -> TokenType: + def from_type(type: TokenType, pos: int = None) -> "Token": return Token(type, None, pos, pos) @staticmethod