Repository navigation
Move type-only imports to TYPE_CHECKING in samplers/_nsgaiii/_sampler.py - #6558
Merged
Merged
Conversation
…i/_sampler.py Move imports only used in type annotations into the `TYPE_CHECKING` block: - `collections.abc.Callable` (only in type hints) - `collections.abc.Sequence` (only in type hints) - `numpy` (only in `np.ndarray` annotation) - `optuna.distributions.BaseDistribution` (only in type annotations) `LazyRandomState`, `TrialState`, and `FrozenTrial` remain as regular imports since `LazyRandomState` is instantiated at runtime (`LazyRandomState(seed)`) and `TrialState` enum values are accessed at runtime. With `from __future__ import annotations`, all annotations are evaluated lazily so the deferred imports are safe. Fixes part of #6029
TYPE_CHECKING in samplers/_nsgaiii/_sampler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move type-only imports in optuna/samplers/_nsgaiii/_sampler.py into the TYPE_CHECKING block, as requested in #6029.
Moved into TYPE_CHECKING: Callable, Sequence (stdlib), numpy (third-party), and BaseDistribution (application). These are only used in type annotations.
Kept as regular imports: LazyRandomState (instantiated at runtime), TrialState (enum values used at runtime), FrozenTrial (objects received at runtime).
Identified by: ruff check . --select TCH
Fixes part of #6029