make mypy happy

This commit is contained in:
Jann Stute
2024-11-27 20:52:07 +01:00
parent eae8d9d571
commit 2bbad4a5d1
3 changed files with 12 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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