Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/superset-python-integrationtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.9", "3.10"]
python-version: ["3.11"]
env:
PYTHONPATH: ${{ github.workspace }}
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
Expand Down
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ babel==2.9.1
# via flask-babel
backoff==1.11.1
# via apache-superset
backports-strenum==1.2.4
# via apache-superset
bcrypt==4.0.1
# via paramiko
billiard==3.6.4.0
Expand Down
4 changes: 1 addition & 3 deletions requirements/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pyasn1-modules==0.3.0
# via python-ldap
pydruid==0.6.5
# via apache-superset
pyhive[hive]==0.6.5
pyhive[hive_pure_sasl]==0.7.1.dev0
# via apache-superset
pyinstrument==4.4.0
# via -r requirements/development.in
Expand All @@ -115,8 +115,6 @@ rfc3986==2.0.0
# via tableschema
s3transfer==0.6.1
# via boto3
sasl==0.3.1
# via pyhive
sqloxide==0.1.33
# via -r requirements/development.in
stack-data==0.6.2
Expand Down
2 changes: 1 addition & 1 deletion requirements/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pydata-google-auth==1.7.0
# via pandas-gbq
pyfakefs==5.2.2
# via -r requirements/testing.in
pyhive[presto]==0.6.5
pyhive[presto]==0.7.1.dev0
# via apache-superset
pymeeus==0.5.12
# via convertdate
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def get_git_sha() -> str:
},
install_requires=[
"backoff>=1.8.0",
"backports.strenum==1.2.4",
"cachelib>=0.4.1,<0.5",
"celery>=5.2.2, <6.0.0",
"click>=8.0.3",
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 backports.strenum 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 backports.strenum 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,10 +21,10 @@
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

from backports.strenum import StrEnum
from flask_appbuilder.security.sqla.models import User
from flask_babel import gettext as __
from sqlalchemy import and_, Boolean, Column, Integer, String, Text
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 backports.strenum 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"
6 changes: 3 additions & 3 deletions superset/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# specific language governing permissions and limitations
# under the License.
from dataclasses import dataclass
from enum import Enum
from typing import Any, Optional

from backports.strenum import StrEnum
from flask_babel import lazy_gettext as _


class SupersetErrorType(str, Enum):
class SupersetErrorType(StrEnum):
"""
Types of errors that can exist within Superset.

Expand Down Expand Up @@ -183,7 +183,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,10 +20,10 @@
import pickle
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Any, TypedDict
from uuid import UUID

from backports.strenum import StrEnum
from marshmallow import Schema, ValidationError

from superset.key_value.exceptions import (
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/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
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

import sqlparse
from backports.strenum import StrEnum
from sqlalchemy import and_
from sqlparse import keywords
from sqlparse.lexer import Lexer
Expand Down Expand Up @@ -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/tasks/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# specific language governing permissions and limitations
# under the License.

from enum import Enum
from backports.strenum import StrEnum


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
29 changes: 15 additions & 14 deletions superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import numpy as np
import pandas as pd
import sqlalchemy as sa
from backports.strenum import StrEnum
from cryptography.hazmat.backends import default_backend
from cryptography.x509 import Certificate, load_pem_x509_certificate
from flask import current_app, flash, g, Markup, request
Expand Down Expand Up @@ -133,12 +134,12 @@ def get(cls, value: Any) -> Any:
return None


class AdhocMetricExpressionType(str, Enum):
class AdhocMetricExpressionType(StrEnum):
SIMPLE = "SIMPLE"
SQL = "SQL"


class AnnotationType(str, Enum):
class AnnotationType(StrEnum):
FORMULA = "FORMULA"
INTERVAL = "INTERVAL"
EVENT = "EVENT"
Expand All @@ -160,7 +161,7 @@ class GenericDataType(IntEnum):
# ROW = 7


class DatasourceType(str, Enum):
class DatasourceType(StrEnum):
SLTABLE = "sl_table"
TABLE = "table"
DATASET = "dataset"
Expand All @@ -169,7 +170,7 @@ class DatasourceType(str, Enum):
VIEW = "view"


class LoggerLevel(str, Enum):
class LoggerLevel(StrEnum):
INFO = "info"
WARNING = "warning"
EXCEPTION = "exception"
Expand Down Expand Up @@ -208,19 +209,19 @@ class QueryObjectFilterClause(TypedDict, total=False):
isExtra: bool | None


class ExtraFiltersTimeColumnType(str, Enum):
class ExtraFiltersTimeColumnType(StrEnum):
TIME_COL = "__time_col"
TIME_GRAIN = "__time_grain"
TIME_ORIGIN = "__time_origin"
TIME_RANGE = "__time_range"


class ExtraFiltersReasonType(str, Enum):
class ExtraFiltersReasonType(StrEnum):
NO_TEMPORAL_COLUMN = "no_temporal_column"
COL_NOT_IN_DATASOURCE = "not_in_datasource"


class FilterOperator(str, Enum):
class FilterOperator(StrEnum):
"""
Operators used filter controls
"""
Expand All @@ -242,7 +243,7 @@ class FilterOperator(str, Enum):
TEMPORAL_RANGE = "TEMPORAL_RANGE"


class FilterStringOperators(str, Enum):
class FilterStringOperators(StrEnum):
EQUALS = ("EQUALS",)
NOT_EQUALS = ("NOT_EQUALS",)
LESS_THAN = ("LESS_THAN",)
Expand All @@ -260,7 +261,7 @@ class FilterStringOperators(str, Enum):
IS_FALSE = ("IS_FALSE",)


class PostProcessingBoxplotWhiskerType(str, Enum):
class PostProcessingBoxplotWhiskerType(StrEnum):
"""
Calculate cell contribution to row/column total
"""
Expand All @@ -270,7 +271,7 @@ class PostProcessingBoxplotWhiskerType(str, Enum):
PERCENTILE = "percentile"


class PostProcessingContributionOrientation(str, Enum):
class PostProcessingContributionOrientation(StrEnum):
"""
Calculate cell contribution to row/column total
"""
Expand Down Expand Up @@ -298,7 +299,7 @@ class QuerySource(Enum):
SQL_LAB = 2


class QueryStatus(str, Enum):
class QueryStatus(StrEnum):
"""Enum-type class for query statuses"""

STOPPED: str = "stopped"
Expand All @@ -311,14 +312,14 @@ class QueryStatus(str, Enum):
TIMED_OUT: str = "timed_out"


class DashboardStatus(str, Enum):
class DashboardStatus(StrEnum):
"""Dashboard status used for frontend filters"""

PUBLISHED = "published"
DRAFT = "draft"


class ReservedUrlParameters(str, Enum):
class ReservedUrlParameters(StrEnum):
"""
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.
Expand All @@ -336,7 +337,7 @@ def is_standalone_mode() -> bool | None:
return standalone


class RowLevelSecurityFilterType(str, Enum):
class RowLevelSecurityFilterType(StrEnum):
REGULAR = "Regular"
BASE = "Base"

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/utils/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@


from contextlib import nullcontext
from enum import Enum
from inspect import isclass
from typing import Any, Optional
from unittest.mock import call, Mock, patch

import pytest
from backports.strenum import StrEnum

from superset import app
from superset.utils import decorators


class ResponseValues(str, Enum):
class ResponseValues(StrEnum):
FAIL = "fail"
WARN = "warn"
OK = "ok"
Expand Down