Skip to content

refactor: move type-only imports into TYPE_CHECKING in samplers/_grid.py#6466

Merged
c-bata merged 1 commit intooptuna:masterfrom
dhruvildarji:refactor/type-checking-samplers-grid
Feb 24, 2026
Merged

refactor: move type-only imports into TYPE_CHECKING in samplers/_grid.py#6466
c-bata merged 1 commit intooptuna:masterfrom
dhruvildarji:refactor/type-checking-samplers-grid

Conversation

@dhruvildarji
Copy link
Copy Markdown
Contributor

Closes #6029

Move Mapping and Sequence (from collections.abc), BaseDistribution, and FrozenTrial into the existing TYPE_CHECKING block in optuna/samplers/_grid.py, since all are only used in type annotations and the file already has from __future__ import annotations.

Verified with ruff check optuna/samplers/_grid.py --select TCH — all checks pass.

Move `Mapping`, `Sequence` (from collections.abc), `BaseDistribution`,
and `FrozenTrial` into the existing TYPE_CHECKING block since they are
only used in type annotations.

Fixes optuna#6029
@c-bata c-bata added the code-fix Change that does not change the behavior, such as code refactoring. label Feb 24, 2026
@c-bata c-bata added this to the v4.8.0 milestone Feb 24, 2026
@c-bata c-bata merged commit 6b7e0e7 into optuna:master Feb 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use TYPE_CHECKING if necessary

2 participants