Skip to content

refactor: move BaseDistribution import to TYPE_CHECKING in search_space/group_decomposed.py - #6553

Merged
c-bata merged 1 commit into
optuna:masterfrom
Aliipou:fix/type-checking-search-space-group-decomposed
Mar 23, 2026
Merged

c-bata merged 1 commit into
optuna:masterfrom
Aliipou:fix/type-checking-search-space-group-decomposed

Conversation

@Aliipou

@Aliipou Aliipou commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

This PR moves the type-only import of BaseDistribution in optuna/search_space/group_decomposed.py into a TYPE_CHECKING block, as requested in #6029.

Changes

  • Move from optuna.distributions import BaseDistribution into the TYPE_CHECKING block
  • BaseDistribution is only used in type annotations (method parameter and return type hints), not at runtime
  • TrialState remains as a regular import since TrialState.COMPLETE and TrialState.PRUNED are accessed at runtime (lines 59, 61)

With from __future__ import annotations already present in this file, all annotations are evaluated lazily, so this import is not needed at runtime.

This was identified by running:

ruff check . --select TCH --output-format=concise

Fixes part of #6029

…ce/group_decomposed.py

Move `from optuna.distributions import BaseDistribution` into the
`TYPE_CHECKING` block since it is only used in type annotations
(method signatures and attribute type hints).

With `from __future__ import annotations` already in place, annotations
are evaluated lazily, so this import is not required at runtime.

`TrialState` is kept as a regular import since `TrialState.COMPLETE` and
`TrialState.PRUNED` are accessed at runtime.

Fixes part of #6029
@c-bata c-bata added the code-fix Change that does not change the behavior, such as code refactoring. label Mar 23, 2026
@c-bata c-bata added this to the v4.9.0 milestone Mar 23, 2026
@c-bata
c-bata merged commit bbbdae8 into optuna:master Mar 23, 2026
13 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.

2 participants