Skip to content

Commit

Permalink
fix: Python3.11 (str, Enum) issue (#24803)
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneTorap authored Jul 31, 2023
1 parent 77889b2 commit 5f10307
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 52 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enable=
# --disable=W"
disable=
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,
duplicate-code,
unspecified-encoding,
Expand Down
6 changes: 3 additions & 3 deletions superset/common/chart_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from enum import Enum
from superset.utils.backports import StrEnum


class ChartDataResultFormat(str, Enum):
class ChartDataResultFormat(StrEnum):
"""
Chart data response format
"""
Expand All @@ -31,7 +31,7 @@ def table_like(cls) -> set["ChartDataResultFormat"]:
return {cls.CSV} | {cls.XLSX}


class ChartDataResultType(str, Enum):
class ChartDataResultType(StrEnum):
"""
Chart data response type
"""
Expand Down
4 changes: 2 additions & 2 deletions superset/common/db_query_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# 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"""

STOPPED: str = "stopped"
Expand Down
4 changes: 2 additions & 2 deletions superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import logging
from collections.abc import Hashable
from datetime import datetime
from enum import Enum
from json.decoder import JSONDecodeError
from typing import Any, TYPE_CHECKING

Expand All @@ -44,6 +43,7 @@
ResultSetColumnType,
)
from superset.utils import core as utils
from superset.utils.backports import StrEnum
from superset.utils.core import GenericDataType, MediumText

if TYPE_CHECKING:
Expand Down Expand Up @@ -75,7 +75,7 @@
]


class DatasourceKind(str, Enum):
class DatasourceKind(StrEnum):
VIRTUAL = "virtual"
PHYSICAL = "physical"

Expand Down
8 changes: 5 additions & 3 deletions superset/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# string to use when None values *need* to be converted to/from strings
from enum import Enum

from superset.utils.backports import StrEnum

USER_AGENT = "Apache Superset"

NULL_STRING = "<NULL>"
Expand Down Expand Up @@ -185,7 +187,7 @@ class RouteMethod: # pylint: disable=too-few-public-methods
)


class TimeGrain(str, Enum):
class TimeGrain(StrEnum):
SECOND = "PT1S"
FIVE_SECONDS = "PT5S"
THIRTY_SECONDS = "PT30S"
Expand Down Expand Up @@ -214,13 +216,13 @@ class PandasAxis(int, Enum):
COLUMN = 1


class PandasPostprocessingCompare(str, Enum):
class PandasPostprocessingCompare(StrEnum):
DIFF = "difference"
PCT = "percentage"
RAT = "ratio"


class CacheRegion(str, Enum):
class CacheRegion(StrEnum):
DEFAULT = "default"
DATA = "data"
THUMBNAIL = "thumbnail"
7 changes: 4 additions & 3 deletions superset/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
# specific language governing permissions and limitations
# under the License.
from dataclasses import dataclass
from enum import Enum
from typing import Any, Optional

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.
Expand Down Expand Up @@ -183,7 +184,7 @@ class SupersetErrorType(str, Enum):
}


class ErrorLevel(str, Enum):
class ErrorLevel(StrEnum):
"""
Levels of errors that can exist within Superset.
Expand Down
6 changes: 3 additions & 3 deletions superset/key_value/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import pickle
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Any, TypedDict
from uuid import UUID

Expand All @@ -30,6 +29,7 @@
KeyValueCodecDecodeException,
KeyValueCodecEncodeException,
)
from superset.utils.backports import StrEnum


@dataclass
Expand All @@ -44,14 +44,14 @@ class KeyValueFilter(TypedDict, total=False):
uuid: UUID | None


class KeyValueResource(str, Enum):
class KeyValueResource(StrEnum):
APP = "app"
DASHBOARD_PERMALINK = "dashboard_permalink"
EXPLORE_PERMALINK = "explore_permalink"
METASTORE_CACHE = "superset_metastore_cache"


class SharedKey(str, Enum):
class SharedKey(StrEnum):
DASHBOARD_PERMALINK_SALT = "dashboard_permalink_salt"
EXPLORE_PERMALINK_SALT = "explore_permalink_salt"

Expand Down
6 changes: 3 additions & 3 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from __future__ import annotations

import builtins
import enum
import json
import logging
import textwrap
Expand Down Expand Up @@ -74,6 +73,7 @@
from superset.result_set import SupersetResultSet
from superset.superset_typing import ResultSetColumnType
from superset.utils import cache as cache_util, core as utils
from superset.utils.backports import StrEnum
from superset.utils.core import get_username

config = app.config
Expand Down Expand Up @@ -116,7 +116,7 @@ class CssTemplate(Model, AuditMixinNullable):
css = Column(Text, default="")


class ConfigurationMethod(str, enum.Enum):
class ConfigurationMethod(StrEnum):
SQLALCHEMY_FORM = "sqlalchemy_form"
DYNAMIC_FORM = "dynamic_form"

Expand Down Expand Up @@ -1007,7 +1007,7 @@ class Log(Model): # pylint: disable=too-few-public-methods
referrer = Column(String(1024))


class FavStarClassName(str, enum.Enum):
class FavStarClassName(StrEnum):
CHART = "slice"
DASHBOARD = "Dashboard"

Expand Down
17 changes: 8 additions & 9 deletions superset/reports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
"""A collection of ORM sqlalchemy models for Superset"""
import enum

from cron_descriptor import get_description
from flask_appbuilder import Model
from flask_appbuilder.models.decorators import renders
Expand All @@ -41,48 +39,49 @@
from superset.models.helpers import AuditMixinNullable, ExtraJSONMixin
from superset.models.slice import Slice
from superset.reports.types import ReportScheduleExtra
from superset.utils.backports import StrEnum

metadata = Model.metadata # pylint: disable=no-member


class ReportScheduleType(str, enum.Enum):
class ReportScheduleType(StrEnum):
ALERT = "Alert"
REPORT = "Report"


class ReportScheduleValidatorType(str, enum.Enum):
class ReportScheduleValidatorType(StrEnum):
"""Validator types for alerts"""

NOT_NULL = "not null"
OPERATOR = "operator"


class ReportRecipientType(str, enum.Enum):
class ReportRecipientType(StrEnum):
EMAIL = "Email"
SLACK = "Slack"


class ReportState(str, enum.Enum):
class ReportState(StrEnum):
SUCCESS = "Success"
WORKING = "Working"
ERROR = "Error"
NOOP = "Not triggered"
GRACE = "On Grace"


class ReportDataFormat(str, enum.Enum):
class ReportDataFormat(StrEnum):
VISUALIZATION = "PNG"
DATA = "CSV"
TEXT = "TEXT"


class ReportCreationMethod(str, enum.Enum):
class ReportCreationMethod(StrEnum):
CHARTS = "charts"
DASHBOARDS = "dashboards"
ALERTS_REPORTS = "alerts_reports"


class ReportSourceFormat(str, enum.Enum):
class ReportSourceFormat(StrEnum):
CHART = "chart"
DASHBOARD = "dashboard"

Expand Down
6 changes: 3 additions & 3 deletions superset/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import re
from collections.abc import Iterator
from dataclasses import dataclass
from enum import Enum
from typing import Any, cast, Optional
from urllib import parse

Expand Down Expand Up @@ -49,6 +48,7 @@
from sqlparse.utils import imt

from superset.exceptions import QueryClauseValidationException
from superset.utils.backports import StrEnum

try:
from sqloxide import parse_sql as sqloxide_parse
Expand All @@ -71,7 +71,7 @@
lex.set_SQL_REGEX(sqlparser_sql_regex)


class CtasMethod(str, Enum):
class CtasMethod(StrEnum):
TABLE = "TABLE"
VIEW = "VIEW"

Expand Down Expand Up @@ -483,7 +483,7 @@ def sanitize_clause(clause: str) -> str:
return clause


class InsertRLSState(str, Enum):
class InsertRLSState(StrEnum):
"""
State machine that scans for WHERE and ON clauses referencing tables.
"""
Expand Down
4 changes: 2 additions & 2 deletions superset/sqllab/limiting_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import enum
from superset.utils.backports import StrEnum


class LimitingFactor(str, enum.Enum):
class LimitingFactor(StrEnum):
QUERY = "QUERY"
DROPDOWN = "DROPDOWN"
QUERY_AND_DROPDOWN = "QUERY_AND_DROPDOWN"
Expand Down
5 changes: 2 additions & 3 deletions superset/tasks/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# 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:
For Alerts & Reports: the "model" refers to the AlertSchedule object
Expand Down
26 changes: 26 additions & 0 deletions superset/utils/backports.py
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 5f10307

Please sign in to comment.