Skip to content

Use TYPE_CHECKING in samplers/_base.py - #6517

Merged
c-bata merged 1 commit into
optuna:masterfrom
saivedant169:refactor/type-checking-samplers-base
Mar 17, 2026
Merged

c-bata merged 1 commit into
optuna:masterfrom
saivedant169:refactor/type-checking-samplers-base

Conversation

@saivedant169

Copy link
Copy Markdown
Contributor

Motivation

Part of #6029.

Description

Move type-only imports into TYPE_CHECKING block in optuna/samplers/_base.py:

  • collections.abc.Callable → TYPE_CHECKING
  • collections.abc.Sequence → TYPE_CHECKING
  • optuna.distributions.BaseDistribution → TYPE_CHECKING
  • optuna.trial.FrozenTrial → TYPE_CHECKING

TrialState remains at module level since it is used as runtime values (TrialState.COMPLETE, TrialState.PRUNED).

ruff check --select TCH passes clean after the change.

Move Callable, Sequence, BaseDistribution, and FrozenTrial into the
TYPE_CHECKING block. TrialState remains at runtime since it is used
as a value (TrialState.COMPLETE, TrialState.PRUNED).

Part of optuna#6029

@c-bata c-bata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@c-bata c-bata added the code-fix Change that does not change the behavior, such as code refactoring. label Mar 17, 2026
@c-bata c-bata added this to the v4.9.0 milestone Mar 17, 2026
@c-bata
c-bata merged commit 9d731e5 into optuna:master Mar 17, 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