Skip to content

Commit 78e0f80

Browse files
Fix dynamic imports in SQLAlchemy dialect components
Remove runtime imports that violate PyAthena development guidelines: - Move ExecutionContext import to top-level in base.py - Move AthenaDDLIdentifierPreparer import to top-level in compiler.py - Remove unnecessary comments from do_execute method This change improves static analysis, code completion, and dependency tracking while maintaining full functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1e573f6 commit 78e0f80

2 files changed

Lines changed: 2 additions & 7 deletions

File tree

pyathena/sqlalchemy/base.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from sqlalchemy import exc, schema, text, types, util
2323
from sqlalchemy.engine import Engine, reflection
2424
from sqlalchemy.engine.default import DefaultDialect
25+
from sqlalchemy.engine.interfaces import ExecutionContext
2526
from sqlalchemy.sql.compiler import (
2627
DDLCompiler,
2728
GenericTypeCompiler,
@@ -378,17 +379,12 @@ def get_indexes(
378379
return [] # pragma: no cover
379380

380381
def do_execute(self, cursor, statement, parameters, context=None):
381-
"""Execute a statement with support for execution_options."""
382-
from sqlalchemy.engine.interfaces import ExecutionContext
383-
384-
# Check for on_start_query_execution in execution_options
385382
on_start_query_execution = None
386383
if isinstance(context, ExecutionContext):
387384
execution_options = context.execution_options
388385
if execution_options is not None:
389386
on_start_query_execution = execution_options.get("on_start_query_execution")
390387

391-
# Execute with callback if specified
392388
if on_start_query_execution is not None:
393389
cursor.execute(statement, parameters, on_start_query_execution=on_start_query_execution)
394390
else:

pyathena/sqlalchemy/compiler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
AthenaPartitionTransform,
1919
AthenaRowFormatSerde,
2020
)
21+
from pyathena.sqlalchemy.preparer import AthenaDDLIdentifierPreparer
2122
from pyathena.sqlalchemy.types import AthenaArray, AthenaMap, AthenaStruct
2223

2324
if TYPE_CHECKING:
@@ -271,8 +272,6 @@ def __init__(
271272
render_schema_translate: bool = False,
272273
compile_kwargs: Optional[Dict[str, Any]] = None,
273274
):
274-
from pyathena.sqlalchemy.preparer import AthenaDDLIdentifierPreparer
275-
276275
self._preparer = AthenaDDLIdentifierPreparer(dialect)
277276
super().__init__(
278277
dialect=dialect,

0 commit comments

Comments
 (0)