mirror of
https://github.com/apache/superset.git
synced 2026-04-14 13:44:46 +00:00
chore(pre-commit): Add pyupgrade and pycln hooks (#24197)
This commit is contained in:
@@ -15,10 +15,11 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Dict, Iterable
|
||||
from collections.abc import Iterable
|
||||
from typing import Any
|
||||
|
||||
|
||||
class ExampleDataGenerator(ABC):
|
||||
@abstractmethod
|
||||
def generate(self) -> Iterable[Dict[Any, Any]]:
|
||||
def generate(self) -> Iterable[dict[Any, Any]]:
|
||||
...
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
# under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
from datetime import datetime
|
||||
from random import choice, randint
|
||||
from typing import Any, Dict, Iterable, TYPE_CHECKING
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
from tests.consts.birth_names import (
|
||||
BOY,
|
||||
@@ -58,7 +59,7 @@ class BirthNamesGenerator(ExampleDataGenerator):
|
||||
self._until_not_include_year = start_year + years_amount
|
||||
self._rows_per_year = rows_per_year
|
||||
|
||||
def generate(self) -> Iterable[Dict[Any, Any]]:
|
||||
def generate(self) -> Iterable[dict[Any, Any]]:
|
||||
for year in range(self._start_year, self._until_not_include_year):
|
||||
ds = self._make_year(year)
|
||||
for _ in range(self._rows_per_year):
|
||||
@@ -67,7 +68,7 @@ class BirthNamesGenerator(ExampleDataGenerator):
|
||||
def _make_year(self, year: int):
|
||||
return datetime(year, 1, 1, 0, 0, 0)
|
||||
|
||||
def generate_row(self, dt: datetime) -> Dict[Any, Any]:
|
||||
def generate_row(self, dt: datetime) -> dict[Any, Any]:
|
||||
gender = choice([BOY, GIRL])
|
||||
num = randint(1, 100000)
|
||||
return {
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, Iterable, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from sqlalchemy.types import TypeEngine
|
||||
|
||||
@@ -33,14 +34,14 @@ from sqlalchemy.types import TypeEngine
|
||||
@dataclass
|
||||
class TableMetaData:
|
||||
table_name: str
|
||||
types: Optional[Dict[str, TypeEngine]]
|
||||
types: Optional[dict[str, TypeEngine]]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Table:
|
||||
table_name: str
|
||||
table_metadata: TableMetaData
|
||||
data: Iterable[Dict[Any, Any]]
|
||||
data: Iterable[dict[Any, Any]]
|
||||
|
||||
|
||||
class TableMetaDataFactory(ABC):
|
||||
@@ -48,6 +49,6 @@ class TableMetaDataFactory(ABC):
|
||||
def make(self) -> TableMetaData:
|
||||
...
|
||||
|
||||
def make_table(self, data: Iterable[Dict[Any, Any]]) -> Table:
|
||||
def make_table(self, data: Iterable[dict[Any, Any]]) -> Table:
|
||||
metadata = self.make()
|
||||
return Table(metadata.table_name, metadata, data)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict, Optional, TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pandas import DataFrame
|
||||
from sqlalchemy.inspection import inspect
|
||||
@@ -63,10 +63,10 @@ class PandasDataLoader(DataLoader):
|
||||
schema=self._detect_schema_name(),
|
||||
)
|
||||
|
||||
def _detect_schema_name(self) -> Optional[str]:
|
||||
def _detect_schema_name(self) -> str | None:
|
||||
return inspect(self._db_engine).default_schema_name
|
||||
|
||||
def _take_data_types(self, table: Table) -> Optional[Dict[str, str]]:
|
||||
def _take_data_types(self, table: Table) -> dict[str, str] | None:
|
||||
if metadata_table := table.table_metadata:
|
||||
types = metadata_table.types
|
||||
if types:
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict
|
||||
from typing import Any
|
||||
|
||||
default_pandas_data_loader_config = {
|
||||
"if_exists": "replace",
|
||||
@@ -54,7 +54,7 @@ class PandasLoaderConfigurations:
|
||||
self.support_datetime_type = support_datetime_type
|
||||
|
||||
@classmethod
|
||||
def make_from_dict(cls, _dict: Dict[str, Any]) -> PandasLoaderConfigurations:
|
||||
def make_from_dict(cls, _dict: dict[str, Any]) -> PandasLoaderConfigurations:
|
||||
copy_dict = default_pandas_data_loader_config.copy()
|
||||
copy_dict.update(_dict)
|
||||
return PandasLoaderConfigurations(**copy_dict) # type: ignore
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pandas import DataFrame
|
||||
|
||||
@@ -30,10 +30,10 @@ if TYPE_CHECKING:
|
||||
@log
|
||||
class TableToDfConvertorImpl(TableToDfConvertor):
|
||||
convert_datetime_to_str: bool
|
||||
_time_format: Optional[str]
|
||||
_time_format: str | None
|
||||
|
||||
def __init__(
|
||||
self, convert_ds_to_datetime: bool, time_format: Optional[str] = None
|
||||
self, convert_ds_to_datetime: bool, time_format: str | None = None
|
||||
) -> None:
|
||||
self.convert_datetime_to_str = convert_ds_to_datetime
|
||||
self._time_format = time_format
|
||||
|
||||
Reference in New Issue
Block a user