Skip to content

Move JSONSerializable import to TYPE_CHECKING in study/study.py#6490

Merged
not522 merged 1 commit intooptuna:masterfrom
yasumorishima:fix/tch-optuna-study-study-py
Mar 4, 2026
Merged

Move JSONSerializable import to TYPE_CHECKING in study/study.py#6490
not522 merged 1 commit intooptuna:masterfrom
yasumorishima:fix/tch-optuna-study-study-py

Conversation

@yasumorishima
Copy link
Copy Markdown
Contributor

Summary

Moves the JSONSerializable import in optuna/study/study.py under a TYPE_CHECKING guard, as it is only used in a type annotation (the params parameter of _should_skip_enqueue).

This is part of the effort tracked in issue #6029.

Changes

  • optuna/study/study.py: Move from optuna.distributions import JSONSerializable to the if TYPE_CHECKING: block

Motivation

JSONSerializable is only referenced in the type annotation of _should_skip_enqueue(self, params: Mapping[str, JSONSerializable]). Moving it under TYPE_CHECKING eliminates the runtime import overhead and follows the pattern established for other type-annotation-only imports in the codebase.

Testing

No behavioral changes. The annotation is only evaluated by type checkers (e.g., mypy), not at runtime.

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.

LGTM

@not522 not522 changed the title fix: move JSONSerializable import to TYPE_CHECKING in study/study.py Move JSONSerializable import to TYPE_CHECKING in study/study.py Mar 4, 2026
@not522 not522 added the code-fix Change that does not change the behavior, such as code refactoring. label Mar 4, 2026
@not522 not522 added this to the v4.8.0 milestone Mar 4, 2026
@not522 not522 merged commit f511608 into optuna:master Mar 4, 2026
14 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