You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2023/05/25 23:00:12 UTC

[superset] 14/18: chore: Update mypy and fix stubs issue (#24033)

This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/superset.git

commit d5cb6cbd19e7e6920a12ee867b626bdd123a3aa7
Author: EugeneTorap <ev...@gmail.com>
AuthorDate: Fri May 12 10:47:14 2023 +0300

    chore: Update mypy and fix stubs issue (#24033)
---
 .pre-commit-config.yaml                            | 17 +++++++++++++++--
 superset/charts/api.py                             |  2 +-
 superset/dashboards/api.py                         |  2 +-
 superset/databases/api.py                          |  2 +-
 superset/datasets/api.py                           |  2 +-
 superset/embedded/view.py                          |  2 ++
 superset/extensions/__init__.py                    |  2 +-
 superset/importexport/api.py                       |  2 +-
 superset/initialization/__init__.py                | 10 +++-------
 superset/jinja_context.py                          |  2 +-
 superset/queries/saved_queries/api.py              |  2 +-
 superset/result_set.py                             |  6 +++---
 superset/sqllab/api.py                             |  4 ++--
 superset/sqllab/query_render.py                    |  4 +---
 superset/utils/encrypt.py                          |  2 +-
 superset/utils/pandas_postprocessing/boxplot.py    |  4 ++--
 superset/utils/url_map_converters.py               |  2 +-
 superset/views/base.py                             |  8 ++++----
 superset/views/core.py                             |  6 ++++--
 superset/views/utils.py                            |  4 ++--
 tests/integration_tests/reports/scheduler_tests.py |  2 +-
 tests/unit_tests/tasks/test_cron_util.py           |  2 +-
 22 files changed, 50 insertions(+), 39 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index aa0cf4af62..fe7ca007e9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -20,10 +20,23 @@ repos:
     hooks:
       - id: isort
   - repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v0.941
+    rev: v1.3.0
     hooks:
       - id: mypy
-        additional_dependencies: [types-all]
+        args: [--check-untyped-defs]
+        additional_dependencies:
+          [
+            types-simplejson,
+            types-python-dateutil,
+            types-requests,
+            types-redis,
+            types-pytz,
+            types-croniter,
+            types-PyYAML,
+            types-setuptools,
+            types-paramiko,
+            types-Markdown,
+          ]
   - repo: https://github.com/peterdemin/pip-compile-multi
     rev: v2.4.1
     hooks:
diff --git a/superset/charts/api.py b/superset/charts/api.py
index 7dc6d5e1e8..4f70f4180a 100644
--- a/superset/charts/api.py
+++ b/superset/charts/api.py
@@ -782,7 +782,7 @@ class ChartRestApi(BaseSupersetModelRestApi):
             buf,
             mimetype="application/zip",
             as_attachment=True,
-            attachment_filename=filename,
+            download_name=filename,
         )
         if token:
             response.set_cookie(token, "done", max_age=600)
diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py
index 64ea637c66..405d15b932 100644
--- a/superset/dashboards/api.py
+++ b/superset/dashboards/api.py
@@ -806,7 +806,7 @@ class DashboardRestApi(BaseSupersetModelRestApi):
                 buf,
                 mimetype="application/zip",
                 as_attachment=True,
-                attachment_filename=filename,
+                download_name=filename,
             )
             if token:
                 response.set_cookie(token, "done", max_age=600)
diff --git a/superset/databases/api.py b/superset/databases/api.py
index c285198747..38040d02c3 100644
--- a/superset/databases/api.py
+++ b/superset/databases/api.py
@@ -1054,7 +1054,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
             buf,
             mimetype="application/zip",
             as_attachment=True,
-            attachment_filename=filename,
+            download_name=filename,
         )
         if token:
             response.set_cookie(token, "done", max_age=600)
diff --git a/superset/datasets/api.py b/superset/datasets/api.py
index d58a1dd3f6..1b644baf00 100644
--- a/superset/datasets/api.py
+++ b/superset/datasets/api.py
@@ -516,7 +516,7 @@ class DatasetRestApi(BaseSupersetModelRestApi):
                 buf,
                 mimetype="application/zip",
                 as_attachment=True,
-                attachment_filename=filename,
+                download_name=filename,
             )
             if token:
                 response.set_cookie(token, "done", max_age=600)
diff --git a/superset/embedded/view.py b/superset/embedded/view.py
index 8dd383aada..b7062c0b5e 100644
--- a/superset/embedded/view.py
+++ b/superset/embedded/view.py
@@ -55,6 +55,8 @@ class EmbeddedView(BaseSupersetView):
         if not embedded:
             abort(404)
 
+        assert embedded is not None
+
         # validate request referrer in allowed domains
         is_referrer_allowed = not embedded.allowed_domains
         for domain in embedded.allowed_domains:
diff --git a/superset/extensions/__init__.py b/superset/extensions/__init__.py
index e2e5592e1e..f633385972 100644
--- a/superset/extensions/__init__.py
+++ b/superset/extensions/__init__.py
@@ -107,7 +107,7 @@ class ProfilingExtension:  # pylint: disable=too-few-public-methods
         self.interval = interval
 
     def init_app(self, app: Flask) -> None:
-        app.wsgi_app = SupersetProfiler(app.wsgi_app, self.interval)  # type: ignore
+        app.wsgi_app = SupersetProfiler(app.wsgi_app, self.interval)
 
 
 APP_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir)
diff --git a/superset/importexport/api.py b/superset/importexport/api.py
index 26bc78e5d7..3a159c140e 100644
--- a/superset/importexport/api.py
+++ b/superset/importexport/api.py
@@ -87,7 +87,7 @@ class ImportExportRestApi(BaseSupersetApi):
             buf,
             mimetype="application/zip",
             as_attachment=True,
-            attachment_filename=filename,
+            download_name=filename,
         )
         return response
 
diff --git a/superset/initialization/__init__.py b/superset/initialization/__init__.py
index ef332e502d..f06dbdb907 100644
--- a/superset/initialization/__init__.py
+++ b/superset/initialization/__init__.py
@@ -564,7 +564,7 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
             CORS(self.superset_app, **self.config["CORS_OPTIONS"])
 
         if self.config["ENABLE_PROXY_FIX"]:
-            self.superset_app.wsgi_app = ProxyFix(  # type: ignore
+            self.superset_app.wsgi_app = ProxyFix(
                 self.superset_app.wsgi_app, **self.config["PROXY_FIX_CONFIG"]
             )
 
@@ -583,9 +583,7 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
                         environ["wsgi.input_terminated"] = True
                     return self.app(environ, start_response)
 
-            self.superset_app.wsgi_app = ChunkedEncodingFix(  # type: ignore
-                self.superset_app.wsgi_app  # type: ignore
-            )
+            self.superset_app.wsgi_app = ChunkedEncodingFix(self.superset_app.wsgi_app)
 
         if self.config["UPLOAD_FOLDER"]:
             try:
@@ -594,9 +592,7 @@ class SupersetAppInitializer:  # pylint: disable=too-many-public-methods
                 pass
 
         for middleware in self.config["ADDITIONAL_MIDDLEWARE"]:
-            self.superset_app.wsgi_app = middleware(  # type: ignore
-                self.superset_app.wsgi_app
-            )
+            self.superset_app.wsgi_app = middleware(self.superset_app.wsgi_app)
 
         # Flask-Compress
         Compress(self.superset_app)
diff --git a/superset/jinja_context.py b/superset/jinja_context.py
index d9409e297b..a72aaf53a3 100644
--- a/superset/jinja_context.py
+++ b/superset/jinja_context.py
@@ -189,7 +189,7 @@ class ExtraCache:
         # pylint: disable=import-outside-toplevel
         from superset.views.utils import get_form_data
 
-        if has_request_context() and request.args.get(param):  # type: ignore
+        if has_request_context() and request.args.get(param):
             return request.args.get(param, default)
 
         form_data, _ = get_form_data()
diff --git a/superset/queries/saved_queries/api.py b/superset/queries/saved_queries/api.py
index 2b70b582bb..5d1fb2d2b2 100644
--- a/superset/queries/saved_queries/api.py
+++ b/superset/queries/saved_queries/api.py
@@ -275,7 +275,7 @@ class SavedQueryRestApi(BaseSupersetModelRestApi):
             buf,
             mimetype="application/zip",
             as_attachment=True,
-            attachment_filename=filename,
+            download_name=filename,
         )
         if token:
             response.set_cookie(token, "done", max_age=600)
diff --git a/superset/result_set.py b/superset/result_set.py
index 1c4ae98dc9..170de1869c 100644
--- a/superset/result_set.py
+++ b/superset/result_set.py
@@ -70,14 +70,14 @@ def stringify_values(array: NDArray[Any]) -> NDArray[Any]:
         for obj in it:
             if na_obj := pd.isna(obj):
                 # pandas <NA> type cannot be converted to string
-                obj[na_obj] = None  # type: ignore
+                obj[na_obj] = None
             else:
                 try:
                     # for simple string conversions
                     # this handles odd character types better
-                    obj[...] = obj.astype(str)  # type: ignore
+                    obj[...] = obj.astype(str)
                 except ValueError:
-                    obj[...] = stringify(obj)  # type: ignore
+                    obj[...] = stringify(obj)
 
     return result
 
diff --git a/superset/sqllab/api.py b/superset/sqllab/api.py
index 5915601c0d..0f7a5236c5 100644
--- a/superset/sqllab/api.py
+++ b/superset/sqllab/api.py
@@ -280,7 +280,7 @@ class SqlLabRestApi(BaseSupersetApi):
         )
         execution_context_convertor = ExecutionContextConvertor()
         execution_context_convertor.set_max_row_in_display(
-            int(config.get("DISPLAY_MAX_ROW"))  # type: ignore
+            int(config.get("DISPLAY_MAX_ROW"))
         )
         return ExecuteSqlCommand(
             execution_context,
@@ -305,7 +305,7 @@ class SqlLabRestApi(BaseSupersetApi):
             sql_json_executor = SynchronousSqlJsonExecutor(
                 query_dao,
                 get_sql_results,
-                config.get("SQLLAB_TIMEOUT"),  # type: ignore
+                config.get("SQLLAB_TIMEOUT"),
                 is_feature_enabled("SQLLAB_BACKEND_PERSISTENCE"),
             )
         return sql_json_executor
diff --git a/superset/sqllab/query_render.py b/superset/sqllab/query_render.py
index 2854a7e390..544b53ad1f 100644
--- a/superset/sqllab/query_render.py
+++ b/superset/sqllab/query_render.py
@@ -76,9 +76,7 @@ class SqlQueryRenderImpl(SqlQueryRender):
         if is_feature_enabled("ENABLE_TEMPLATE_PROCESSING"):
             # pylint: disable=protected-access
             syntax_tree = sql_template_processor._env.parse(rendered_query)
-            undefined_parameters = find_undeclared_variables(  # type: ignore
-                syntax_tree
-            )
+            undefined_parameters = find_undeclared_variables(syntax_tree)
             if undefined_parameters:
                 self._raise_undefined_parameter_exception(
                     execution_context, undefined_parameters
diff --git a/superset/utils/encrypt.py b/superset/utils/encrypt.py
index 0c230c6cd9..52b784bb23 100644
--- a/superset/utils/encrypt.py
+++ b/superset/utils/encrypt.py
@@ -60,7 +60,7 @@ class EncryptedFieldFactory:
 
     def init_app(self, app: Flask) -> None:
         self._config = app.config
-        self._concrete_type_adapter = self._config[
+        self._concrete_type_adapter = self._config[  # type: ignore
             "SQLALCHEMY_ENCRYPTED_FIELD_TYPE_ADAPTER"
         ]()
 
diff --git a/superset/utils/pandas_postprocessing/boxplot.py b/superset/utils/pandas_postprocessing/boxplot.py
index d4c78bf15e..399cf569fb 100644
--- a/superset/utils/pandas_postprocessing/boxplot.py
+++ b/superset/utils/pandas_postprocessing/boxplot.py
@@ -99,8 +99,8 @@ def boxplot(
             return np.nanpercentile(series, low)
 
     else:
-        whisker_high = np.max  # type: ignore
-        whisker_low = np.min  # type: ignore
+        whisker_high = np.max
+        whisker_low = np.min
 
     def outliers(series: Series) -> Set[float]:
         above = series[series > whisker_high(series)]
diff --git a/superset/utils/url_map_converters.py b/superset/utils/url_map_converters.py
index c5eaf3b359..fbd9c800b0 100644
--- a/superset/utils/url_map_converters.py
+++ b/superset/utils/url_map_converters.py
@@ -23,7 +23,7 @@ from superset.tags.models import ObjectTypes
 
 class RegexConverter(BaseConverter):
     def __init__(self, url_map: Map, *items: List[str]) -> None:
-        super().__init__(url_map)  # type: ignore
+        super().__init__(url_map)
         self.regex = items[0]
 
 
diff --git a/superset/views/base.py b/superset/views/base.py
index ec74b8ccdb..f4a945484c 100644
--- a/superset/views/base.py
+++ b/superset/views/base.py
@@ -486,7 +486,7 @@ def show_http_exception(ex: HTTPException) -> FlaskResponse:
         and ex.code in {404, 500}
     ):
         path = resource_filename("superset", f"static/assets/{ex.code}.html")
-        return send_file(path, cache_timeout=0), ex.code
+        return send_file(path, max_age=0), ex.code
 
     return json_errors_response(
         errors=[
@@ -508,7 +508,7 @@ def show_command_errors(ex: CommandException) -> FlaskResponse:
     logger.warning("CommandException", exc_info=True)
     if "text/html" in request.accept_mimetypes and not config["DEBUG"]:
         path = resource_filename("superset", "static/assets/500.html")
-        return send_file(path, cache_timeout=0), 500
+        return send_file(path, max_age=0), 500
 
     extra = ex.normalized_messages() if isinstance(ex, CommandInvalidError) else {}
     return json_errors_response(
@@ -530,7 +530,7 @@ def show_unexpected_exception(ex: Exception) -> FlaskResponse:
     logger.exception(ex)
     if "text/html" in request.accept_mimetypes and not config["DEBUG"]:
         path = resource_filename("superset", "static/assets/500.html")
-        return send_file(path, cache_timeout=0), 500
+        return send_file(path, max_age=0), 500
 
     return json_errors_response(
         errors=[
@@ -729,7 +729,7 @@ def apply_http_headers(response: Response) -> Response:
     """Applies the configuration's http headers to all responses"""
 
     # HTTP_HEADERS is deprecated, this provides backwards compatibility
-    response.headers.extend(  # type: ignore
+    response.headers.extend(
         {**config["OVERRIDE_HTTP_HEADERS"], **config["HTTP_HEADERS"]}
     )
 
diff --git a/superset/views/core.py b/superset/views/core.py
index b1580756b7..7f6364bb8a 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1844,6 +1844,8 @@ class Superset(BaseSupersetView):  # pylint: disable=too-many-public-methods
         if not dashboard:
             abort(404)
 
+        assert dashboard is not None
+
         has_access_ = False
         for datasource in dashboard.datasources:
             datasource = DatasourceDAO.get_datasource(
@@ -2367,7 +2369,7 @@ class Superset(BaseSupersetView):  # pylint: disable=too-many-public-methods
         )
         execution_context_convertor = ExecutionContextConvertor()
         execution_context_convertor.set_max_row_in_display(
-            int(config.get("DISPLAY_MAX_ROW"))  # type: ignore
+            int(config.get("DISPLAY_MAX_ROW"))
         )
         return ExecuteSqlCommand(
             execution_context,
@@ -2392,7 +2394,7 @@ class Superset(BaseSupersetView):  # pylint: disable=too-many-public-methods
             sql_json_executor = SynchronousSqlJsonExecutor(
                 query_dao,
                 get_sql_results,
-                config.get("SQLLAB_TIMEOUT"),  # type: ignore
+                config.get("SQLLAB_TIMEOUT"),
                 is_feature_enabled("SQLLAB_BACKEND_PERSISTENCE"),
             )
         return sql_json_executor
diff --git a/superset/views/utils.py b/superset/views/utils.py
index cd84d8e0a5..35a39fdc9c 100644
--- a/superset/views/utils.py
+++ b/superset/views/utils.py
@@ -153,7 +153,7 @@ def get_form_data(  # pylint: disable=too-many-locals
 ) -> Tuple[Dict[str, Any], Optional[Slice]]:
     form_data: Dict[str, Any] = initial_form_data or {}
 
-    if has_request_context():  # type: ignore
+    if has_request_context():
         # chart data API requests are JSON
         request_json_data = (
             request.json["queries"][0]
@@ -186,7 +186,7 @@ def get_form_data(  # pylint: disable=too-many-locals
         json_data = form_data["queries"][0] if "queries" in form_data else {}
         form_data.update(json_data)
 
-    if has_request_context():  # type: ignore
+    if has_request_context():
         url_id = request.args.get("r")
         if url_id:
             saved_url = db.session.query(models.Url).filter_by(id=url_id).first()
diff --git a/tests/integration_tests/reports/scheduler_tests.py b/tests/integration_tests/reports/scheduler_tests.py
index 3dd6e72941..d121e87d45 100644
--- a/tests/integration_tests/reports/scheduler_tests.py
+++ b/tests/integration_tests/reports/scheduler_tests.py
@@ -22,7 +22,7 @@ from unittest.mock import patch
 import pytest
 from flask_appbuilder.security.sqla.models import User
 from freezegun import freeze_time
-from freezegun.api import FakeDatetime  # type: ignore
+from freezegun.api import FakeDatetime
 
 from superset.extensions import db
 from superset.reports.models import ReportScheduleType
diff --git a/tests/unit_tests/tasks/test_cron_util.py b/tests/unit_tests/tasks/test_cron_util.py
index d0f9ae2170..282dc99860 100644
--- a/tests/unit_tests/tasks/test_cron_util.py
+++ b/tests/unit_tests/tasks/test_cron_util.py
@@ -21,7 +21,7 @@ import pytest
 import pytz
 from dateutil import parser
 from freezegun import freeze_time
-from freezegun.api import FakeDatetime  # type: ignore
+from freezegun.api import FakeDatetime
 
 from superset.tasks.cron_util import cron_schedule_window