Skip to content

Move type-only imports to TYPE_CHECKING in test_visualizations.py#6380

Merged
not522 merged 3 commits intooptuna:masterfrom
Sip4818:type-check-visualizations
Dec 10, 2025
Merged

Move type-only imports to TYPE_CHECKING in test_visualizations.py#6380
not522 merged 3 commits intooptuna:masterfrom
Sip4818:type-check-visualizations

Conversation

@Sip4818
Copy link
Copy Markdown
Contributor

@Sip4818 Sip4818 commented Dec 9, 2025

Motivation

This PR updates one of the files listed in the type-checking cleanup effort. In tests/visualization_tests/test_visualizations.py, certain imports were used only for type annotations. These should be placed under a TYPE_CHECKING block to avoid unnecessary runtime imports, reduce import overhead, prevent potential circular imports, and improve consistency in static type checking across the codebase.

Description of the changes

  • Moved type-only imports (Trial, ObjectiveFuncType) into a TYPE_CHECKING block.
  • Reformatted long lines to comply with flake8 (E501).
  • No functional behavior was changed; all tests remain the same.

Related to #6029

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 added the code-fix Change that does not change the behavior, such as code refactoring. label Dec 10, 2025
@not522 not522 added this to the v4.7.0 milestone Dec 10, 2025
@not522 not522 changed the title Move type-only imports to TYPE_CHECKING in test_visualizations.py Move type-only imports to TYPE_CHECKING in test_visualizations.py Dec 10, 2025
@not522 not522 merged commit c24cc70 into optuna:master Dec 10, 2025
14 checks passed
@Sip4818 Sip4818 deleted the type-check-visualizations branch December 10, 2025 08:30
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