From 95bffb7391be4d29f47102c5d37fe001023144f8 Mon Sep 17 00:00:00 2001 From: surister Date: Tue, 4 Jun 2024 15:15:39 +0200 Subject: [PATCH] Fix formatting --- .../cratedb_sqlparse/parser.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cratedb_sqlparse_py/cratedb_sqlparse/parser.py b/cratedb_sqlparse_py/cratedb_sqlparse/parser.py index e3a861b..4a8ca58 100644 --- a/cratedb_sqlparse_py/cratedb_sqlparse/parser.py +++ b/cratedb_sqlparse_py/cratedb_sqlparse/parser.py @@ -1,7 +1,7 @@ import logging from typing import List -from antlr4 import CommonTokenStream, InputStream, Token, RecognitionException +from antlr4 import CommonTokenStream, InputStream, RecognitionException, Token from antlr4.error.ErrorListener import ErrorListener from cratedb_sqlparse.generated_parser.SqlBaseLexer import SqlBaseLexer @@ -44,17 +44,19 @@ def error_message(self): @property def original_query_with_error_marked(self): query = self.offending_token.source[1].strdata - offending_token_text: str = query[self.offending_token.start: self.offending_token.stop + 1] - query_lines: list = query.split('\n') + offending_token_text: str = query[self.offending_token.start : self.offending_token.stop + 1] + query_lines: list = query.split("\n") offending_line: str = query_lines[self.line - 1] # White spaces from the beginning of the offending line to the offending text, so the '^' # chars are correctly placed below the offending token. newline_offset = offending_line.index(offending_token_text) - newline = offending_line + '\n' + ( - ' ' * newline_offset + '^' * ( - self.offending_token.stop - self.offending_token.start + 1)) + newline = ( + offending_line + + "\n" + + (" " * newline_offset + "^" * (self.offending_token.stop - self.offending_token.start + 1)) + ) query_lines[self.line - 1] = newline @@ -70,7 +72,7 @@ def line(self): return self.offending_token.line def __repr__(self): - return f'{type(self.e).__qualname__}' + return f"{type(self.e).__qualname__}" def __str__(self): return repr(self) @@ -94,7 +96,7 @@ def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): msg=msg, offending_token=offendingSymbol, e=e, - query=e.ctx.parser.getTokenStream().getText(e.ctx.start, e.offendingToken.tokenIndex) + query=e.ctx.parser.getTokenStream().getText(e.ctx.start, e.offendingToken.tokenIndex), ) raise error @@ -148,8 +150,7 @@ def query(self) -> str: """ Returns the query, comments and ';' are not included. """ - return self.ctx.parser.getTokenStream().getText(start=self.ctx.start, - stop=self.ctx.stop) + return self.ctx.parser.getTokenStream().getText(start=self.ctx.start, stop=self.ctx.stop) @property def type(self): @@ -167,8 +168,8 @@ def find_suitable_error(statement, errors): # We clean the error_query of ';' and spaces because ironically, # we can get the full query in the error handler but not in the context. error_query = error.query - if error_query.endswith(';'): - error_query = error_query[:len(error_query) - 1] + if error_query.endswith(";"): + error_query = error_query[: len(error_query) - 1] if error_query.lstrip().rstrip() == statement.query: statement.exception = error @@ -192,8 +193,7 @@ def sqlparse(query: str, raise_exception: bool = False) -> List[Statement]: tree = parser.statements() statements_context: list[SqlBaseParser.StatementContext] = list( - filter(lambda children: isinstance(children, SqlBaseParser.StatementContext), - tree.children) + filter(lambda children: isinstance(children, SqlBaseParser.StatementContext), tree.children) ) statements = [] @@ -222,7 +222,7 @@ def sqlparse(query: str, raise_exception: bool = False) -> List[Statement]: if len(error_listener.errors) > 1: logging.error( - 'Could not match errors to queries, too much ambiguity, open an issue with this error and the query.' + "Could not match errors to queries, too much ambiguity, open an issue with this error and the query." ) return statements