Skip to content

Move type-only imports to TYPE_CHECKING in _constrained_optimization.py#6381

Merged
not522 merged 1 commit intooptuna:masterfrom
Sip4818:type-hint-cleanup-2
Dec 11, 2025
Merged

Move type-only imports to TYPE_CHECKING in _constrained_optimization.py#6381
not522 merged 1 commit intooptuna:masterfrom
Sip4818:type-hint-cleanup-2

Conversation

@Sip4818
Copy link
Copy Markdown
Contributor

@Sip4818 Sip4818 commented Dec 10, 2025

Motivation

This PR is part of the type-checking cleanup effort. In optuna/study/_constrained_optimization.py, the FrozenTrial import is used only for type annotations and is not needed at runtime. Moving it under a TYPE_CHECKING block reduces unnecessary runtime imports and aligns the file with Optuna's type-hinting conventions.

Description of the changes

  • Moved the type-only import FrozenTrial into a TYPE_CHECKING block.
  • No functional behavior was changed.

Related to #6029

@not522 not522 changed the title Move type-only imports to TYPE_CHECKING in optuna/study/_constrained_optimization.py Move type-only imports to TYPE_CHECKING in _constrained_optimization.py Dec 11, 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 added the code-fix Change that does not change the behavior, such as code refactoring. label Dec 11, 2025
@not522 not522 added this to the v4.7.0 milestone Dec 11, 2025
@not522 not522 merged commit 9b345dc into optuna:master Dec 11, 2025
14 checks passed
@Sip4818 Sip4818 deleted the type-hint-cleanup-2 branch December 11, 2025 06:56
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