mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore(pre-commit): Add pyupgrade and pycln hooks (#24197)
This commit is contained in:
@@ -21,8 +21,9 @@ import os
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
from collections.abc import Iterator
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from typing import Any, Callable, cast, Dict, Iterator, List, Optional, Type
|
||||
from typing import Any, Callable, cast, Optional
|
||||
from uuid import uuid4
|
||||
|
||||
import sqlalchemy.sql.sqltypes
|
||||
@@ -39,17 +40,14 @@ from superset import db
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
ColumnInfo = TypedDict(
|
||||
"ColumnInfo",
|
||||
{
|
||||
"name": str,
|
||||
"type": VisitableType,
|
||||
"nullable": bool,
|
||||
"default": Optional[Any],
|
||||
"autoincrement": str,
|
||||
"primary_key": int,
|
||||
},
|
||||
)
|
||||
|
||||
class ColumnInfo(TypedDict):
|
||||
name: str
|
||||
type: VisitableType
|
||||
nullable: bool
|
||||
default: Optional[Any]
|
||||
autoincrement: str
|
||||
primary_key: int
|
||||
|
||||
|
||||
example_column = {
|
||||
@@ -167,7 +165,7 @@ def get_type_generator( # pylint: disable=too-many-return-statements,too-many-b
|
||||
|
||||
|
||||
def add_data(
|
||||
columns: Optional[List[ColumnInfo]],
|
||||
columns: Optional[list[ColumnInfo]],
|
||||
num_rows: int,
|
||||
table_name: str,
|
||||
append: bool = True,
|
||||
@@ -212,16 +210,16 @@ def add_data(
|
||||
engine.execute(table.insert(), data)
|
||||
|
||||
|
||||
def get_column_objects(columns: List[ColumnInfo]) -> List[Column]:
|
||||
def get_column_objects(columns: list[ColumnInfo]) -> list[Column]:
|
||||
out = []
|
||||
for column in columns:
|
||||
kwargs = cast(Dict[str, Any], column.copy())
|
||||
kwargs = cast(dict[str, Any], column.copy())
|
||||
kwargs["type_"] = kwargs.pop("type")
|
||||
out.append(Column(**kwargs))
|
||||
return out
|
||||
|
||||
|
||||
def generate_data(columns: List[ColumnInfo], num_rows: int) -> List[Dict[str, Any]]:
|
||||
def generate_data(columns: list[ColumnInfo], num_rows: int) -> list[dict[str, Any]]:
|
||||
keys = [column["name"] for column in columns]
|
||||
return [
|
||||
dict(zip(keys, row))
|
||||
@@ -229,13 +227,13 @@ def generate_data(columns: List[ColumnInfo], num_rows: int) -> List[Dict[str, An
|
||||
]
|
||||
|
||||
|
||||
def generate_column_data(column: ColumnInfo, num_rows: int) -> List[Any]:
|
||||
def generate_column_data(column: ColumnInfo, num_rows: int) -> list[Any]:
|
||||
gen = get_type_generator(column["type"])
|
||||
return [gen() for _ in range(num_rows)]
|
||||
|
||||
|
||||
def add_sample_rows(
|
||||
session: Session, model: Type[Model], count: int
|
||||
session: Session, model: type[Model], count: int
|
||||
) -> Iterator[Model]:
|
||||
"""
|
||||
Add entities of a given model.
|
||||
|
||||
Reference in New Issue
Block a user