chore(pre-commit): Add pyupgrade and pycln hooks (#24197)

This commit is contained in:
John Bodley
2023-06-01 12:01:10 -07:00
committed by GitHub
parent 7d7ce63970
commit a4d5d7c6b9
448 changed files with 3084 additions and 3305 deletions

View File

@@ -14,13 +14,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Optional, Type
from typing import Optional
from . import base, postgres, presto_db
from .base import SQLValidationAnnotation
def get_validator_by_name(name: str) -> Optional[Type[base.BaseSQLValidator]]:
def get_validator_by_name(name: str) -> Optional[type[base.BaseSQLValidator]]:
return {
"PrestoDBSQLValidator": presto_db.PrestoDBSQLValidator,
"PostgreSQLValidator": postgres.PostgreSQLValidator,

View File

@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any, Dict, List, Optional
from typing import Any, Optional
from superset.models.core import Database
@@ -34,7 +34,7 @@ class SQLValidationAnnotation: # pylint: disable=too-few-public-methods
self.start_column = start_column
self.end_column = end_column
def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> dict[str, Any]:
"""Return a dictionary representation of this annotation"""
return {
"line_number": self.line_number,
@@ -53,6 +53,6 @@ class BaseSQLValidator: # pylint: disable=too-few-public-methods
@classmethod
def validate(
cls, sql: str, schema: Optional[str], database: Database
) -> List[SQLValidationAnnotation]:
) -> list[SQLValidationAnnotation]:
"""Check that the given SQL querystring is valid for the given engine"""
raise NotImplementedError

View File

@@ -16,7 +16,7 @@
# under the License.
import re
from typing import List, Optional
from typing import Optional
from pgsanity.pgsanity import check_string
@@ -32,8 +32,8 @@ class PostgreSQLValidator(BaseSQLValidator): # pylint: disable=too-few-public-m
@classmethod
def validate(
cls, sql: str, schema: Optional[str], database: Database
) -> List[SQLValidationAnnotation]:
annotations: List[SQLValidationAnnotation] = []
) -> list[SQLValidationAnnotation]:
annotations: list[SQLValidationAnnotation] = []
valid, error = check_string(sql, add_semicolon=True)
if valid:
return annotations

View File

@@ -18,7 +18,7 @@
import logging
import time
from contextlib import closing
from typing import Any, Dict, List, Optional
from typing import Any, Optional
from superset import app, security_manager
from superset.models.core import Database
@@ -109,7 +109,7 @@ class PrestoDBSQLValidator(BaseSQLValidator):
raise PrestoSQLValidationError(
"The pyhive presto client returned an unhandled " "database error."
) from db_error
error_args: Dict[str, Any] = db_error.args[0]
error_args: dict[str, Any] = db_error.args[0]
# Confirm the two fields we need to be able to present an annotation
# are present in the error response -- a message, and a location.
@@ -148,7 +148,7 @@ class PrestoDBSQLValidator(BaseSQLValidator):
@classmethod
def validate(
cls, sql: str, schema: Optional[str], database: Database
) -> List[SQLValidationAnnotation]:
) -> list[SQLValidationAnnotation]:
"""
Presto supports query-validation queries by running them with a
prepended explain.
@@ -167,7 +167,7 @@ class PrestoDBSQLValidator(BaseSQLValidator):
) as engine:
# Sharing a single connection and cursor across the
# execution of all statements (if many)
annotations: List[SQLValidationAnnotation] = []
annotations: list[SQLValidationAnnotation] = []
with closing(engine.raw_connection()) as conn:
cursor = conn.cursor()
for statement in parsed_query.get_statements():