Skip to content

Move typing-only imports under TYPE_CHECKING in optuna.importance.__init__#6278

Merged
nabenabe0928 merged 1 commit intooptuna:masterfrom
euangoodbrand:type-check
Sep 17, 2025
Merged

Move typing-only imports under TYPE_CHECKING in optuna.importance.__init__#6278
nabenabe0928 merged 1 commit intooptuna:masterfrom
euangoodbrand:type-check

Conversation

@euangoodbrand
Copy link
Copy Markdown
Contributor

Description
This PR improves type checking in the optuna.importance module by moving imports that are only used for typing under a TYPE_CHECKING guard.

Motivation

  • Reduces unnecessary runtime imports.
  • Ensures cleaner separation between runtime and type-only dependencies.
  • Aligns with Optuna’s type-checking conventions (see Use TYPE_CHECKING if necessary #6029).

Changes

  • Updated optuna/importance/__init__.py so that Callable, Study, and FrozenTrial are imported only when TYPE_CHECKING is enabled.

Notes

  • No runtime behaviour changes observed.
  • Verified with mypy, 'flake8' and pytest -- all checks pass locally for the change.

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 added the code-fix Change that does not change the behavior, such as code refactoring. label Sep 17, 2025
@nabenabe0928 nabenabe0928 added this to the v4.6.0 milestone Sep 17, 2025
@nabenabe0928 nabenabe0928 merged commit 7d10514 into optuna:master Sep 17, 2025
15 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