fix(sql-lab): address minor type-hint nits from codeant review

Add explicit type annotations for the `blocks` list in sql_lab.py and
the mock/cursor test variables, and replace an untyped lambda mutator
with a typed helper to keep MUTATE_AFTER_SPLIT type-hint coverage
consistent with the rest of the PR.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Evan
2026-07-14 08:44:34 -07:00
parent bf85efdbb7
commit ed510633ce
3 changed files with 19 additions and 6 deletions

View File

@@ -77,6 +77,11 @@ def mock_query() -> MagicMock:
return query
def _passthrough_mutate_sql_based_on_config(sql: str, **kwargs: Any) -> str:
"""Mirror the real `Database.mutate_sql_based_on_config` no-op default."""
return sql
@pytest.fixture
def mock_database() -> MagicMock:
"""Create a mock Database."""
@@ -97,7 +102,9 @@ def mock_database() -> MagicMock:
# Mirrors the real `Database.mutate_sql_based_on_config` default (no-op
# when no `SQL_QUERY_MUTATOR` is configured), so SQL parsed from its
# return value stays valid instead of an un-parseable `MagicMock`.
database.mutate_sql_based_on_config = MagicMock(side_effect=lambda sql, **kw: sql)
database.mutate_sql_based_on_config = MagicMock(
side_effect=_passthrough_mutate_sql_based_on_config
)
return database

View File

@@ -47,7 +47,11 @@ from superset.models.core import Database
# Note: database, database_with_dml, mock_db_session fixtures and
# mock_query_execution helper are imported from conftest.py
from .conftest import create_mock_cursor, mock_query_execution
from .conftest import (
_passthrough_mutate_sql_based_on_config,
create_mock_cursor,
mock_query_execution,
)
# =============================================================================
# Basic Execution Tests
@@ -889,14 +893,16 @@ def test_execute_sql_with_cursor_forwards_is_split(
"""
from superset.sql.execution.executor import execute_sql_with_cursor
mutate_mock = mocker.patch.object(
database, "mutate_sql_based_on_config", side_effect=lambda sql, **kw: sql
mutate_mock: MagicMock = mocker.patch.object(
database,
"mutate_sql_based_on_config",
side_effect=_passthrough_mutate_sql_based_on_config,
)
mocker.patch.object(database.db_engine_spec, "execute")
mocker.patch.object(database.db_engine_spec, "fetch_data", return_value=[(1,)])
mocker.patch("superset.result_set.SupersetResultSet", return_value=MagicMock())
cursor = create_mock_cursor(["id"], data=[(1,)])
cursor: MagicMock = create_mock_cursor(["id"], data=[(1,)])
execute_sql_with_cursor(
database=database,