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

@@ -81,7 +81,7 @@ def test_get_text_clause_with_colon() -> None:
from superset.db_engine_specs.athena import AthenaEngineSpec
query = (
"SELECT foo FROM tbl WHERE " "abc >= TIMESTAMP '2021-11-26T00\:00\:00.000000'"
"SELECT foo FROM tbl WHERE " r"abc >= TIMESTAMP '2021-11-26T00\:00\:00.000000'"
)
text_clause = AthenaEngineSpec.get_text_clause(query)
assert text_clause.text == query

View File

@@ -17,7 +17,7 @@
# pylint: disable=unused-argument, import-outside-toplevel, protected-access
from textwrap import dedent
from typing import Any, Dict, Optional, Type
from typing import Any, Optional
import pytest
from sqlalchemy import types
@@ -130,8 +130,8 @@ def test_cte_query_parsing(original: types.TypeEngine, expected: str) -> None:
)
def test_get_column_spec(
native_type: str,
sqla_type: Type[types.TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[types.TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:

View File

@@ -16,7 +16,7 @@
# under the License.
from datetime import datetime
from typing import Any, Dict, Optional, Type
from typing import Any, Optional
from unittest.mock import Mock
import pytest
@@ -189,8 +189,8 @@ def test_connect_convert_dttm(
)
def test_connect_get_column_spec(
native_type: str,
sqla_type: Type[TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:

View File

@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
from datetime import datetime
from typing import Any, Dict, Optional
from typing import Any, Optional
from unittest.mock import MagicMock
import pytest
@@ -49,7 +49,7 @@ from tests.unit_tests.fixtures.common import dttm
)
def test_elasticsearch_convert_dttm(
target_type: str,
db_extra: Optional[Dict[str, Any]],
db_extra: Optional[dict[str, Any]],
expected_result: Optional[str],
dttm: datetime,
) -> None:

View File

@@ -17,7 +17,7 @@
import unittest.mock as mock
from datetime import datetime
from textwrap import dedent
from typing import Any, Dict, Optional, Type
from typing import Any, Optional
import pytest
from sqlalchemy import column, table
@@ -50,8 +50,8 @@ from tests.unit_tests.fixtures.common import dttm
)
def test_get_column_spec(
native_type: str,
sqla_type: Type[TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:

View File

@@ -16,7 +16,7 @@
# under the License.
from datetime import datetime
from typing import Any, Dict, Optional, Tuple, Type
from typing import Any, Optional
from unittest.mock import Mock, patch
import pytest
@@ -71,8 +71,8 @@ from tests.unit_tests.fixtures.common import dttm
)
def test_get_column_spec(
native_type: str,
sqla_type: Type[types.TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[types.TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:
@@ -166,7 +166,7 @@ def test_validate_database_uri(sqlalchemy_uri: str, error: bool) -> None:
],
)
def test_adjust_engine_params(
sqlalchemy_uri: str, connect_args: Dict[str, Any], returns: Dict[str, Any]
sqlalchemy_uri: str, connect_args: dict[str, Any], returns: dict[str, Any]
) -> None:
from superset.db_engine_specs.mysql import MySQLEngineSpec

View File

@@ -17,7 +17,7 @@
# pylint: disable=import-outside-toplevel
from typing import Any, Callable, Dict, List, Optional, Tuple
from typing import Any, Callable
import pytest
@@ -33,7 +33,7 @@ def ocient_is_installed() -> bool:
# (msg,expected)
MARSHALED_OCIENT_ERRORS: List[Tuple[str, SupersetError]] = [
MARSHALED_OCIENT_ERRORS: list[tuple[str, SupersetError]] = [
(
"The referenced user does not exist (User 'mj' not found)",
SupersetError(
@@ -224,7 +224,7 @@ def test_connection_errors(msg: str, expected: SupersetError) -> None:
def _generate_gis_type_sanitization_test_cases() -> (
List[Tuple[str, int, Any, Dict[str, Any]]]
list[tuple[str, int, Any, dict[str, Any]]]
):
if not ocient_is_installed():
return []

View File

@@ -16,7 +16,7 @@
# under the License.
from datetime import datetime
from typing import Any, Dict, Optional, Type
from typing import Any, Optional
import pytest
from sqlalchemy import types
@@ -82,8 +82,8 @@ def test_convert_dttm(
)
def test_get_column_spec(
native_type: str,
sqla_type: Type[types.TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[types.TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:

View File

@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
from datetime import datetime
from typing import Any, Dict, Optional, Type
from typing import Any, Optional
from unittest import mock
import pytest
@@ -77,8 +77,8 @@ def test_convert_dttm(
)
def test_get_column_spec(
native_type: str,
sqla_type: Type[types.TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[types.TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:

View File

@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
from typing import Any, Dict, Optional, Type
from typing import Any, Optional
import pytest
from sqlalchemy import types
@@ -45,8 +45,8 @@ from tests.unit_tests.db_engine_specs.utils import assert_column_spec
)
def test_get_column_spec(
native_type: str,
sqla_type: Type[types.TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[types.TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:
@@ -74,9 +74,9 @@ def test_get_column_spec(
)
def test_adjust_engine_params(
sqlalchemy_uri: str,
connect_args: Dict[str, Any],
connect_args: dict[str, Any],
return_schema: str,
return_connect_args: Dict[str, Any],
return_connect_args: dict[str, Any],
) -> None:
from superset.db_engine_specs.starrocks import StarRocksEngineSpec

View File

@@ -17,7 +17,7 @@
# pylint: disable=unused-argument, import-outside-toplevel, protected-access
import json
from datetime import datetime
from typing import Any, Dict, Optional, Type
from typing import Any, Optional
from unittest.mock import Mock, patch
import pandas as pd
@@ -57,7 +57,7 @@ from tests.unit_tests.fixtures.common import dttm
),
],
)
def test_get_extra_params(extra: Dict[str, Any], expected: Dict[str, Any]) -> None:
def test_get_extra_params(extra: dict[str, Any], expected: dict[str, Any]) -> None:
from superset.db_engine_specs.trino import TrinoEngineSpec
database = Mock()
@@ -95,7 +95,7 @@ def test_auth_basic(mock_auth: Mock) -> None:
{"auth_method": "basic", "auth_params": auth_params}
)
params: Dict[str, Any] = {}
params: dict[str, Any] = {}
TrinoEngineSpec.update_params_from_encrypted_extra(database, params)
connect_args = params.setdefault("connect_args", {})
assert connect_args.get("http_scheme") == "https"
@@ -117,7 +117,7 @@ def test_auth_kerberos(mock_auth: Mock) -> None:
{"auth_method": "kerberos", "auth_params": auth_params}
)
params: Dict[str, Any] = {}
params: dict[str, Any] = {}
TrinoEngineSpec.update_params_from_encrypted_extra(database, params)
connect_args = params.setdefault("connect_args", {})
assert connect_args.get("http_scheme") == "https"
@@ -134,7 +134,7 @@ def test_auth_certificate(mock_auth: Mock) -> None:
{"auth_method": "certificate", "auth_params": auth_params}
)
params: Dict[str, Any] = {}
params: dict[str, Any] = {}
TrinoEngineSpec.update_params_from_encrypted_extra(database, params)
connect_args = params.setdefault("connect_args", {})
assert connect_args.get("http_scheme") == "https"
@@ -152,7 +152,7 @@ def test_auth_jwt(mock_auth: Mock) -> None:
{"auth_method": "jwt", "auth_params": auth_params}
)
params: Dict[str, Any] = {}
params: dict[str, Any] = {}
TrinoEngineSpec.update_params_from_encrypted_extra(database, params)
connect_args = params.setdefault("connect_args", {})
assert connect_args.get("http_scheme") == "https"
@@ -176,7 +176,7 @@ def test_auth_custom_auth() -> None:
{"trino": {"custom_auth": auth_class}},
clear=True,
):
params: Dict[str, Any] = {}
params: dict[str, Any] = {}
TrinoEngineSpec.update_params_from_encrypted_extra(database, params)
connect_args = params.setdefault("connect_args", {})
@@ -243,8 +243,8 @@ def test_auth_custom_auth_denied() -> None:
)
def test_get_column_spec(
native_type: str,
sqla_type: Type[types.TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[types.TypeEngine],
attrs: Optional[dict[str, Any]],
generic_type: GenericDataType,
is_dttm: bool,
) -> None:
@@ -324,8 +324,8 @@ def test_cancel_query_failed(engine_mock: Mock) -> None:
],
)
def test_prepare_cancel_query(
initial_extra: Dict[str, Any],
final_extra: Dict[str, Any],
initial_extra: dict[str, Any],
final_extra: dict[str, Any],
mocker: MockerFixture,
) -> None:
from superset.db_engine_specs.trino import TrinoEngineSpec

View File

@@ -17,7 +17,7 @@
from __future__ import annotations
from datetime import datetime
from typing import Any, Dict, Optional, Type, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from sqlalchemy import types
@@ -28,11 +28,11 @@ if TYPE_CHECKING:
def assert_convert_dttm(
db_engine_spec: Type[BaseEngineSpec],
db_engine_spec: type[BaseEngineSpec],
target_type: str,
expected_result: Optional[str],
expected_result: str | None,
dttm: datetime,
db_extra: Optional[Dict[str, Any]] = None,
db_extra: dict[str, Any] | None = None,
) -> None:
for target in (
target_type,
@@ -50,10 +50,10 @@ def assert_convert_dttm(
def assert_column_spec(
db_engine_spec: Type[BaseEngineSpec],
db_engine_spec: type[BaseEngineSpec],
native_type: str,
sqla_type: Type[types.TypeEngine],
attrs: Optional[Dict[str, Any]],
sqla_type: type[types.TypeEngine],
attrs: dict[str, Any] | None,
generic_type: GenericDataType,
is_dttm: bool,
) -> None: