11import logging
22from typing import List
33
4- from antlr4 import CommonTokenStream , InputStream , Token , RecognitionException
4+ from antlr4 import CommonTokenStream , InputStream , RecognitionException , Token
55from antlr4 .error .ErrorListener import ErrorListener
66
77from cratedb_sqlparse .generated_parser .SqlBaseLexer import SqlBaseLexer
@@ -44,17 +44,19 @@ def error_message(self):
4444 @property
4545 def original_query_with_error_marked (self ):
4646 query = self .offending_token .source [1 ].strdata
47- offending_token_text : str = query [self .offending_token .start : self .offending_token .stop + 1 ]
48- query_lines : list = query .split (' \n ' )
47+ offending_token_text : str = query [self .offending_token .start : self .offending_token .stop + 1 ]
48+ query_lines : list = query .split (" \n " )
4949
5050 offending_line : str = query_lines [self .line - 1 ]
5151
5252 # White spaces from the beginning of the offending line to the offending text, so the '^'
5353 # chars are correctly placed below the offending token.
5454 newline_offset = offending_line .index (offending_token_text )
55- newline = offending_line + '\n ' + (
56- ' ' * newline_offset + '^' * (
57- self .offending_token .stop - self .offending_token .start + 1 ))
55+ newline = (
56+ offending_line
57+ + "\n "
58+ + (" " * newline_offset + "^" * (self .offending_token .stop - self .offending_token .start + 1 ))
59+ )
5860
5961 query_lines [self .line - 1 ] = newline
6062
@@ -70,7 +72,7 @@ def line(self):
7072 return self .offending_token .line
7173
7274 def __repr__ (self ):
73- return f' { type (self .e ).__qualname__ } '
75+ return f" { type (self .e ).__qualname__ } "
7476
7577 def __str__ (self ):
7678 return repr (self )
@@ -94,7 +96,7 @@ def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
9496 msg = msg ,
9597 offending_token = offendingSymbol ,
9698 e = e ,
97- query = e .ctx .parser .getTokenStream ().getText (e .ctx .start , e .offendingToken .tokenIndex )
99+ query = e .ctx .parser .getTokenStream ().getText (e .ctx .start , e .offendingToken .tokenIndex ),
98100 )
99101 raise error
100102
@@ -148,8 +150,7 @@ def query(self) -> str:
148150 """
149151 Returns the query, comments and ';' are not included.
150152 """
151- return self .ctx .parser .getTokenStream ().getText (start = self .ctx .start ,
152- stop = self .ctx .stop )
153+ return self .ctx .parser .getTokenStream ().getText (start = self .ctx .start , stop = self .ctx .stop )
153154
154155 @property
155156 def type (self ):
@@ -167,8 +168,8 @@ def find_suitable_error(statement, errors):
167168 # We clean the error_query of ';' and spaces because ironically,
168169 # we can get the full query in the error handler but not in the context.
169170 error_query = error .query
170- if error_query .endswith (';' ):
171- error_query = error_query [:len (error_query ) - 1 ]
171+ if error_query .endswith (";" ):
172+ error_query = error_query [: len (error_query ) - 1 ]
172173
173174 if error_query .lstrip ().rstrip () == statement .query :
174175 statement .exception = error
@@ -192,8 +193,7 @@ def sqlparse(query: str, raise_exception: bool = False) -> List[Statement]:
192193 tree = parser .statements ()
193194
194195 statements_context : list [SqlBaseParser .StatementContext ] = list (
195- filter (lambda children : isinstance (children , SqlBaseParser .StatementContext ),
196- tree .children )
196+ filter (lambda children : isinstance (children , SqlBaseParser .StatementContext ), tree .children )
197197 )
198198
199199 statements = []
@@ -222,7 +222,7 @@ def sqlparse(query: str, raise_exception: bool = False) -> List[Statement]:
222222
223223 if len (error_listener .errors ) > 1 :
224224 logging .error (
225- ' Could not match errors to queries, too much ambiguity, open an issue with this error and the query.'
225+ " Could not match errors to queries, too much ambiguity, open an issue with this error and the query."
226226 )
227227
228228 return statements
0 commit comments