fix: Python3.11 (str, Enum) issue (#24803)

This commit is contained in:
EugeneTorap 2023-07-31 19:04:09 +03:00 committed by GitHub
parent 77889b29fb
commit 5f103072b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 81 additions and 52 deletions

View File

@ -75,6 +75,7 @@ enable=
# --disable=W" # --disable=W"
disable= disable=
cyclic-import, # re-enable once this no longer raises false positives cyclic-import, # re-enable once this no longer raises false positives
no-member, # re-enable once this no longer raises false positives. This will become redundant after the min required version is 3.11
missing-docstring, missing-docstring,
duplicate-code, duplicate-code,
unspecified-encoding, unspecified-encoding,

View File

@ -14,10 +14,10 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
from enum import Enum from superset.utils.backports import StrEnum
class ChartDataResultFormat(str, Enum): class ChartDataResultFormat(StrEnum):
""" """
Chart data response format Chart data response format
""" """
@ -31,7 +31,7 @@ class ChartDataResultFormat(str, Enum):
return {cls.CSV} | {cls.XLSX} return {cls.CSV} | {cls.XLSX}
class ChartDataResultType(str, Enum): class ChartDataResultType(StrEnum):
""" """
Chart data response type Chart data response type
""" """

View File

@ -14,10 +14,10 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
from enum import Enum from superset.utils.backports import StrEnum
class QueryStatus(str, Enum): class QueryStatus(StrEnum):
"""Enum-type class for query statuses""" """Enum-type class for query statuses"""
STOPPED: str = "stopped" STOPPED: str = "stopped"

View File

@ -21,7 +21,6 @@ import json
import logging import logging
from collections.abc import Hashable from collections.abc import Hashable
from datetime import datetime from datetime import datetime
from enum import Enum
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from typing import Any, TYPE_CHECKING from typing import Any, TYPE_CHECKING
@ -44,6 +43,7 @@ from superset.superset_typing import (
ResultSetColumnType, ResultSetColumnType,
) )
from superset.utils import core as utils from superset.utils import core as utils
from superset.utils.backports import StrEnum
from superset.utils.core import GenericDataType, MediumText from superset.utils.core import GenericDataType, MediumText
if TYPE_CHECKING: if TYPE_CHECKING:
@ -75,7 +75,7 @@ COLUMN_FORM_DATA_PARAMS = [
] ]
class DatasourceKind(str, Enum): class DatasourceKind(StrEnum):
VIRTUAL = "virtual" VIRTUAL = "virtual"
PHYSICAL = "physical" PHYSICAL = "physical"

View File

@ -20,6 +20,8 @@
# string to use when None values *need* to be converted to/from strings # string to use when None values *need* to be converted to/from strings
from enum import Enum from enum import Enum
from superset.utils.backports import StrEnum
USER_AGENT = "Apache Superset" USER_AGENT = "Apache Superset"
NULL_STRING = "<NULL>" NULL_STRING = "<NULL>"
@ -185,7 +187,7 @@ EXTRA_FORM_DATA_OVERRIDE_KEYS = (
) )
class TimeGrain(str, Enum): class TimeGrain(StrEnum):
SECOND = "PT1S" SECOND = "PT1S"
FIVE_SECONDS = "PT5S" FIVE_SECONDS = "PT5S"
THIRTY_SECONDS = "PT30S" THIRTY_SECONDS = "PT30S"
@ -214,13 +216,13 @@ class PandasAxis(int, Enum):
COLUMN = 1 COLUMN = 1
class PandasPostprocessingCompare(str, Enum): class PandasPostprocessingCompare(StrEnum):
DIFF = "difference" DIFF = "difference"
PCT = "percentage" PCT = "percentage"
RAT = "ratio" RAT = "ratio"
class CacheRegion(str, Enum): class CacheRegion(StrEnum):
DEFAULT = "default" DEFAULT = "default"
DATA = "data" DATA = "data"
THUMBNAIL = "thumbnail" THUMBNAIL = "thumbnail"

View File

@ -15,13 +15,14 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum
from typing import Any, Optional from typing import Any, Optional
from flask_babel import lazy_gettext as _ from flask_babel import lazy_gettext as _
from superset.utils.backports import StrEnum
class SupersetErrorType(str, Enum):
class SupersetErrorType(StrEnum):
""" """
Types of errors that can exist within Superset. Types of errors that can exist within Superset.
@ -183,7 +184,7 @@ ERROR_TYPES_TO_ISSUE_CODES_MAPPING = {
} }
class ErrorLevel(str, Enum): class ErrorLevel(StrEnum):
""" """
Levels of errors that can exist within Superset. Levels of errors that can exist within Superset.

View File

@ -20,7 +20,6 @@ import json
import pickle import pickle
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum
from typing import Any, TypedDict from typing import Any, TypedDict
from uuid import UUID from uuid import UUID
@ -30,6 +29,7 @@ from superset.key_value.exceptions import (
KeyValueCodecDecodeException, KeyValueCodecDecodeException,
KeyValueCodecEncodeException, KeyValueCodecEncodeException,
) )
from superset.utils.backports import StrEnum
@dataclass @dataclass
@ -44,14 +44,14 @@ class KeyValueFilter(TypedDict, total=False):
uuid: UUID | None uuid: UUID | None
class KeyValueResource(str, Enum): class KeyValueResource(StrEnum):
APP = "app" APP = "app"
DASHBOARD_PERMALINK = "dashboard_permalink" DASHBOARD_PERMALINK = "dashboard_permalink"
EXPLORE_PERMALINK = "explore_permalink" EXPLORE_PERMALINK = "explore_permalink"
METASTORE_CACHE = "superset_metastore_cache" METASTORE_CACHE = "superset_metastore_cache"
class SharedKey(str, Enum): class SharedKey(StrEnum):
DASHBOARD_PERMALINK_SALT = "dashboard_permalink_salt" DASHBOARD_PERMALINK_SALT = "dashboard_permalink_salt"
EXPLORE_PERMALINK_SALT = "explore_permalink_salt" EXPLORE_PERMALINK_SALT = "explore_permalink_salt"

View File

@ -20,7 +20,6 @@
from __future__ import annotations from __future__ import annotations
import builtins import builtins
import enum
import json import json
import logging import logging
import textwrap import textwrap
@ -74,6 +73,7 @@ from superset.models.helpers import AuditMixinNullable, ImportExportMixin
from superset.result_set import SupersetResultSet from superset.result_set import SupersetResultSet
from superset.superset_typing import ResultSetColumnType from superset.superset_typing import ResultSetColumnType
from superset.utils import cache as cache_util, core as utils from superset.utils import cache as cache_util, core as utils
from superset.utils.backports import StrEnum
from superset.utils.core import get_username from superset.utils.core import get_username
config = app.config config = app.config
@ -116,7 +116,7 @@ class CssTemplate(Model, AuditMixinNullable):
css = Column(Text, default="") css = Column(Text, default="")
class ConfigurationMethod(str, enum.Enum): class ConfigurationMethod(StrEnum):
SQLALCHEMY_FORM = "sqlalchemy_form" SQLALCHEMY_FORM = "sqlalchemy_form"
DYNAMIC_FORM = "dynamic_form" DYNAMIC_FORM = "dynamic_form"
@ -1007,7 +1007,7 @@ class Log(Model): # pylint: disable=too-few-public-methods
referrer = Column(String(1024)) referrer = Column(String(1024))
class FavStarClassName(str, enum.Enum): class FavStarClassName(StrEnum):
CHART = "slice" CHART = "slice"
DASHBOARD = "Dashboard" DASHBOARD = "Dashboard"

View File

@ -15,8 +15,6 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
"""A collection of ORM sqlalchemy models for Superset""" """A collection of ORM sqlalchemy models for Superset"""
import enum
from cron_descriptor import get_description from cron_descriptor import get_description
from flask_appbuilder import Model from flask_appbuilder import Model
from flask_appbuilder.models.decorators import renders from flask_appbuilder.models.decorators import renders
@ -41,28 +39,29 @@ from superset.models.dashboard import Dashboard
from superset.models.helpers import AuditMixinNullable, ExtraJSONMixin from superset.models.helpers import AuditMixinNullable, ExtraJSONMixin
from superset.models.slice import Slice from superset.models.slice import Slice
from superset.reports.types import ReportScheduleExtra from superset.reports.types import ReportScheduleExtra
from superset.utils.backports import StrEnum
metadata = Model.metadata # pylint: disable=no-member metadata = Model.metadata # pylint: disable=no-member
class ReportScheduleType(str, enum.Enum): class ReportScheduleType(StrEnum):
ALERT = "Alert" ALERT = "Alert"
REPORT = "Report" REPORT = "Report"
class ReportScheduleValidatorType(str, enum.Enum): class ReportScheduleValidatorType(StrEnum):
"""Validator types for alerts""" """Validator types for alerts"""
NOT_NULL = "not null" NOT_NULL = "not null"
OPERATOR = "operator" OPERATOR = "operator"
class ReportRecipientType(str, enum.Enum): class ReportRecipientType(StrEnum):
EMAIL = "Email" EMAIL = "Email"
SLACK = "Slack" SLACK = "Slack"
class ReportState(str, enum.Enum): class ReportState(StrEnum):
SUCCESS = "Success" SUCCESS = "Success"
WORKING = "Working" WORKING = "Working"
ERROR = "Error" ERROR = "Error"
@ -70,19 +69,19 @@ class ReportState(str, enum.Enum):
GRACE = "On Grace" GRACE = "On Grace"
class ReportDataFormat(str, enum.Enum): class ReportDataFormat(StrEnum):
VISUALIZATION = "PNG" VISUALIZATION = "PNG"
DATA = "CSV" DATA = "CSV"
TEXT = "TEXT" TEXT = "TEXT"
class ReportCreationMethod(str, enum.Enum): class ReportCreationMethod(StrEnum):
CHARTS = "charts" CHARTS = "charts"
DASHBOARDS = "dashboards" DASHBOARDS = "dashboards"
ALERTS_REPORTS = "alerts_reports" ALERTS_REPORTS = "alerts_reports"
class ReportSourceFormat(str, enum.Enum): class ReportSourceFormat(StrEnum):
CHART = "chart" CHART = "chart"
DASHBOARD = "dashboard" DASHBOARD = "dashboard"

View File

@ -18,7 +18,6 @@ import logging
import re import re
from collections.abc import Iterator from collections.abc import Iterator
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum
from typing import Any, cast, Optional from typing import Any, cast, Optional
from urllib import parse from urllib import parse
@ -49,6 +48,7 @@ from sqlparse.tokens import (
from sqlparse.utils import imt from sqlparse.utils import imt
from superset.exceptions import QueryClauseValidationException from superset.exceptions import QueryClauseValidationException
from superset.utils.backports import StrEnum
try: try:
from sqloxide import parse_sql as sqloxide_parse from sqloxide import parse_sql as sqloxide_parse
@ -71,7 +71,7 @@ sqlparser_sql_regex.insert(25, (r"'(''|\\\\|\\|[^'])*'", sqlparse.tokens.String.
lex.set_SQL_REGEX(sqlparser_sql_regex) lex.set_SQL_REGEX(sqlparser_sql_regex)
class CtasMethod(str, Enum): class CtasMethod(StrEnum):
TABLE = "TABLE" TABLE = "TABLE"
VIEW = "VIEW" VIEW = "VIEW"
@ -483,7 +483,7 @@ def sanitize_clause(clause: str) -> str:
return clause return clause
class InsertRLSState(str, Enum): class InsertRLSState(StrEnum):
""" """
State machine that scans for WHERE and ON clauses referencing tables. State machine that scans for WHERE and ON clauses referencing tables.
""" """

View File

@ -14,10 +14,10 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
import enum from superset.utils.backports import StrEnum
class LimitingFactor(str, enum.Enum): class LimitingFactor(StrEnum):
QUERY = "QUERY" QUERY = "QUERY"
DROPDOWN = "DROPDOWN" DROPDOWN = "DROPDOWN"
QUERY_AND_DROPDOWN = "QUERY_AND_DROPDOWN" QUERY_AND_DROPDOWN = "QUERY_AND_DROPDOWN"

View File

@ -14,11 +14,10 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
from superset.utils.backports import StrEnum
from enum import Enum
class ExecutorType(str, Enum): class ExecutorType(StrEnum):
""" """
Which user should scheduled tasks be executed as. Used as follows: Which user should scheduled tasks be executed as. Used as follows:
For Alerts & Reports: the "model" refers to the AlertSchedule object For Alerts & Reports: the "model" refers to the AlertSchedule object

View File

@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import sys
from enum import Enum
if sys.version_info >= (3, 11):
# pylint: disable=unused-import
from enum import StrEnum # nopycln: import
else:
class StrEnum(str, Enum):
pass

View File

@ -98,6 +98,7 @@ from superset.superset_typing import (
FormData, FormData,
Metric, Metric,
) )
from superset.utils.backports import StrEnum
from superset.utils.database import get_example_database from superset.utils.database import get_example_database
from superset.utils.date_parser import parse_human_timedelta from superset.utils.date_parser import parse_human_timedelta
from superset.utils.dates import datetime_to_epoch, EPOCH from superset.utils.dates import datetime_to_epoch, EPOCH
@ -133,12 +134,12 @@ class LenientEnum(Enum):
return None return None
class AdhocMetricExpressionType(str, Enum): class AdhocMetricExpressionType(StrEnum):
SIMPLE = "SIMPLE" SIMPLE = "SIMPLE"
SQL = "SQL" SQL = "SQL"
class AnnotationType(str, Enum): class AnnotationType(StrEnum):
FORMULA = "FORMULA" FORMULA = "FORMULA"
INTERVAL = "INTERVAL" INTERVAL = "INTERVAL"
EVENT = "EVENT" EVENT = "EVENT"
@ -160,7 +161,7 @@ class GenericDataType(IntEnum):
# ROW = 7 # ROW = 7
class DatasourceType(str, Enum): class DatasourceType(StrEnum):
SLTABLE = "sl_table" SLTABLE = "sl_table"
TABLE = "table" TABLE = "table"
DATASET = "dataset" DATASET = "dataset"
@ -169,7 +170,7 @@ class DatasourceType(str, Enum):
VIEW = "view" VIEW = "view"
class LoggerLevel(str, Enum): class LoggerLevel(StrEnum):
INFO = "info" INFO = "info"
WARNING = "warning" WARNING = "warning"
EXCEPTION = "exception" EXCEPTION = "exception"
@ -208,19 +209,19 @@ class QueryObjectFilterClause(TypedDict, total=False):
isExtra: bool | None isExtra: bool | None
class ExtraFiltersTimeColumnType(str, Enum): class ExtraFiltersTimeColumnType(StrEnum):
TIME_COL = "__time_col" TIME_COL = "__time_col"
TIME_GRAIN = "__time_grain" TIME_GRAIN = "__time_grain"
TIME_ORIGIN = "__time_origin" TIME_ORIGIN = "__time_origin"
TIME_RANGE = "__time_range" TIME_RANGE = "__time_range"
class ExtraFiltersReasonType(str, Enum): class ExtraFiltersReasonType(StrEnum):
NO_TEMPORAL_COLUMN = "no_temporal_column" NO_TEMPORAL_COLUMN = "no_temporal_column"
COL_NOT_IN_DATASOURCE = "not_in_datasource" COL_NOT_IN_DATASOURCE = "not_in_datasource"
class FilterOperator(str, Enum): class FilterOperator(StrEnum):
""" """
Operators used filter controls Operators used filter controls
""" """
@ -242,7 +243,7 @@ class FilterOperator(str, Enum):
TEMPORAL_RANGE = "TEMPORAL_RANGE" TEMPORAL_RANGE = "TEMPORAL_RANGE"
class FilterStringOperators(str, Enum): class FilterStringOperators(StrEnum):
EQUALS = ("EQUALS",) EQUALS = ("EQUALS",)
NOT_EQUALS = ("NOT_EQUALS",) NOT_EQUALS = ("NOT_EQUALS",)
LESS_THAN = ("LESS_THAN",) LESS_THAN = ("LESS_THAN",)
@ -260,7 +261,7 @@ class FilterStringOperators(str, Enum):
IS_FALSE = ("IS_FALSE",) IS_FALSE = ("IS_FALSE",)
class PostProcessingBoxplotWhiskerType(str, Enum): class PostProcessingBoxplotWhiskerType(StrEnum):
""" """
Calculate cell contribution to row/column total Calculate cell contribution to row/column total
""" """
@ -270,7 +271,7 @@ class PostProcessingBoxplotWhiskerType(str, Enum):
PERCENTILE = "percentile" PERCENTILE = "percentile"
class PostProcessingContributionOrientation(str, Enum): class PostProcessingContributionOrientation(StrEnum):
""" """
Calculate cell contribution to row/column total Calculate cell contribution to row/column total
""" """
@ -298,7 +299,7 @@ class QuerySource(Enum):
SQL_LAB = 2 SQL_LAB = 2
class QueryStatus(str, Enum): class QueryStatus(StrEnum):
"""Enum-type class for query statuses""" """Enum-type class for query statuses"""
STOPPED: str = "stopped" STOPPED: str = "stopped"
@ -311,14 +312,14 @@ class QueryStatus(str, Enum):
TIMED_OUT: str = "timed_out" TIMED_OUT: str = "timed_out"
class DashboardStatus(str, Enum): class DashboardStatus(StrEnum):
"""Dashboard status used for frontend filters""" """Dashboard status used for frontend filters"""
PUBLISHED = "published" PUBLISHED = "published"
DRAFT = "draft" DRAFT = "draft"
class ReservedUrlParameters(str, Enum): class ReservedUrlParameters(StrEnum):
""" """
Reserved URL parameters that are used internally by Superset. These will not be Reserved URL parameters that are used internally by Superset. These will not be
passed to chart queries, as they control the behavior of the UI. passed to chart queries, as they control the behavior of the UI.
@ -336,7 +337,7 @@ class ReservedUrlParameters(str, Enum):
return standalone return standalone
class RowLevelSecurityFilterType(str, Enum): class RowLevelSecurityFilterType(StrEnum):
REGULAR = "Regular" REGULAR = "Regular"
BASE = "Base" BASE = "Base"

View File

@ -17,7 +17,6 @@
from contextlib import nullcontext from contextlib import nullcontext
from enum import Enum
from inspect import isclass from inspect import isclass
from typing import Any, Optional from typing import Any, Optional
from unittest.mock import call, Mock, patch from unittest.mock import call, Mock, patch
@ -26,9 +25,10 @@ import pytest
from superset import app from superset import app
from superset.utils import decorators from superset.utils import decorators
from superset.utils.backports import StrEnum
class ResponseValues(str, Enum): class ResponseValues(StrEnum):
FAIL = "fail" FAIL = "fail"
WARN = "warn" WARN = "warn"
OK = "ok" OK = "ok"