Skip to content

Move FrozenTrial import under TYPE_CHECKING for _study_summary.py file#6386

Merged
not522 merged 1 commit intooptuna:masterfrom
Sip4818:type-hint-check-5
Dec 15, 2025
Merged

Move FrozenTrial import under TYPE_CHECKING for _study_summary.py file#6386
not522 merged 1 commit intooptuna:masterfrom
Sip4818:type-hint-check-5

Conversation

@Sip4818
Copy link
Copy Markdown
Contributor

@Sip4818 Sip4818 commented Dec 12, 2025

Description

This PR addresses part of issue #6029: "Use TYPE_CHECKING if necessary" by moving the import of FrozenTrial in study_summary.py under a TYPE_CHECKING block.

FrozenTrial is only used for type annotations in this module and is not required at runtime. Moving this import under TYPE_CHECKING reduces unnecessary runtime imports and aligns with Optuna's ongoing cleanup of typing-only imports.

Changes

  • This PR moves the FrozenTrial import so that it is only loaded during type checking, since it is not needed at runtime.
  • There are no runtime behavior changes.

@Sip4818 Sip4818 closed this Dec 13, 2025
@Sip4818 Sip4818 reopened this Dec 13, 2025
@not522 not522 changed the title Move FrozenTrial import under 'TYPE_CHECKING' for _study_summary.py file Move FrozenTrial import under TYPE_CHECKING for _study_summary.py file Dec 15, 2025
@not522 not522 added the code-fix Change that does not change the behavior, such as code refactoring. label Dec 15, 2025
@not522 not522 added this to the v4.7.0 milestone Dec 15, 2025
Copy link
Copy Markdown
Member

@not522 not522 left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM!

@not522 not522 merged commit 3643f9e into optuna:master Dec 15, 2025
25 of 26 checks passed
@Sip4818 Sip4818 deleted the type-hint-check-5 branch December 15, 2025 14:20
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