Skip to content

Use TYPE_CHECKING in optuna/pruners/_nop.py#6297

Merged
nabenabe0928 merged 2 commits intooptuna:masterfrom
AddyM:fix/type-checking-pruners-nop
Oct 14, 2025
Merged

Use TYPE_CHECKING in optuna/pruners/_nop.py#6297
nabenabe0928 merged 2 commits intooptuna:masterfrom
AddyM:fix/type-checking-pruners-nop

Conversation

@AddyM
Copy link
Copy Markdown
Contributor

@AddyM AddyM commented Oct 11, 2025

Description

Move Study and FrozenTrial imports into TYPE_CHECKING block to avoid potential circular import issues.

Changes

  • Added from typing import TYPE_CHECKING
  • Moved Study and FrozenTrial imports into if TYPE_CHECKING: block
  • Simplified type annotations from "optuna.study.Study" to "Study"
  • Simplified type annotations from optuna.trial.FrozenTrial. to FrozenTrial
  • Kept import optuna with # noqa: F401, TC001 as it's used in docstring examples

Verification

  • Ran flake8 and confirmed no errors
  • Formatted with black and isort

Related to:

Move Study and FrozenTrial imports into TYPE_CHECKING block
to avoid potential circular import issues. Keep 'import optuna'
at runtime as it's used in docstring examples.

Fixes optuna#6029
@AddyM
Copy link
Copy Markdown
Contributor Author

AddyM commented Oct 11, 2025

There is a failure with the run : I checked the logs, This appears to be a transient network issue unrelated to my changes. Could you please re-run the CI checks?

Thanks!

@nabenabe0928 nabenabe0928 changed the title Use TYPE_CHECKING in optuna/pruners/_nop.py Use TYPE_CHECKING in optuna/pruners/_nop.py Oct 12, 2025
@nabenabe0928 nabenabe0928 added the code-fix Change that does not change the behavior, such as code refactoring. label Oct 12, 2025
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
@AddyM AddyM requested a review from nabenabe0928 October 12, 2025 21:15
Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

LGTM!

@nabenabe0928 nabenabe0928 merged commit b5f97f3 into optuna:master Oct 14, 2025
15 checks passed
@nabenabe0928 nabenabe0928 added this to the v4.6.0 milestone Oct 14, 2025
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