chore: Update mypy and fix stubs issue (#24033)

This commit is contained in:
EugeneTorap 2023-05-12 10:47:14 +03:00 committed by GitHub
parent 7fe0ca12c0
commit 4a828f57f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 49 additions and 39 deletions

View File

@ -20,11 +20,23 @@ repos:
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
rev: v1.3.0
hooks:
- id: mypy
args: [--check-untyped-defs]
additional_dependencies: [types-all]
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.6.2
hooks:

View File

@ -805,7 +805,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)

View File

@ -819,7 +819,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)

View File

@ -1058,7 +1058,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)

View File

@ -524,7 +524,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)

View File

@ -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:

View File

@ -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)

View File

@ -87,7 +87,7 @@ class ImportExportRestApi(BaseSupersetApi):
buf,
mimetype="application/zip",
as_attachment=True,
attachment_filename=filename,
download_name=filename,
)
return response

View File

@ -587,7 +587,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"]
)
@ -606,9 +606,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:
@ -617,9 +615,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)

View File

@ -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()

View File

@ -284,7 +284,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)

View File

@ -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

View File

@ -334,7 +334,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,
@ -359,7 +359,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

View File

@ -75,9 +75,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

View File

@ -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"
]()

View File

@ -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)]

View File

@ -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]

View File

@ -490,7 +490,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=[
@ -512,7 +512,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(
@ -534,7 +534,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=[
@ -733,7 +733,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"]}
)

View File

@ -1888,6 +1888,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(
@ -2419,7 +2421,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,
@ -2444,7 +2446,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

View File

@ -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()

View File

@ -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

View File

@ -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