Skip to content

Remove dead code: unused functions, methods, and variables - #6547

Merged
not522 merged 2 commits into
optuna:masterfrom
duriantaco:remove-dead-code
Mar 23, 2026
Merged

not522 merged 2 commits into
optuna:masterfrom
duriantaco:remove-dead-code

Conversation

@duriantaco

Copy link
Copy Markdown
Contributor

Summary

  • Remove _is_distribution_log() in distributions.py — private function with zero callers in production code (only called by its own test)
  • Remove _get_param_values() in visualization/_utils.py — zero callers anywhere in the codebase
  • Remove _LabelEncoder.fit_transform() in visualization/matplotlib/_contour.py — never called (fit() and transform() are always used separately)
  • Remove _log_2 in samplers/_tpe/_truncnorm.py — assigned but never referenced
  • Replace unused unpacked variables (cat_param_labels_x, cat_param_pos_x, cat_param_labels_y, cat_param_pos_y) with _ in _calculate_griddata()
  • Remove test_is_distribution_log test (tested function no longer exists)

0 additions, 31 deletions across 5 files.

Found using Skylos static analysis with LLM verification (28 initial findings → 17 false positives removed → 11 confirmed dead → 6 selected for this PR after excluding auto-generated protobuf code and intentional patterns).

Test plan

  • Existing CI tests pass (no callers of removed code)
  • Verified each removal with grep -r across the full repo (including tests/) to confirm zero references

- `_is_distribution_log()` in distributions.py — zero callers in production code
- `_get_param_values()` in visualization/_utils.py — zero callers
- `_LabelEncoder.fit_transform()` in visualization/matplotlib/_contour.py — never called (fit/transform used separately)
- `_log_2` in samplers/_tpe/_truncnorm.py — assigned but never referenced
- Unused unpacked variables in `_calculate_griddata()` — replaced with `_`
- Removed test for `_is_distribution_log()` (tested function no longer exists)

Found using Skylos static analysis + LLM verification.
@duriantaco

Copy link
Copy Markdown
Contributor Author

Sorry had to rerun Ruff - forgot about it.

@not522 not522 added the code-fix Change that does not change the behavior, such as code refactoring. label Mar 23, 2026
@not522 not522 added this to the v4.9.0 milestone Mar 23, 2026

@not522 not522 left a comment

Copy link
Copy Markdown
Member

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 merged commit 5afeb44 into optuna:master Mar 23, 2026
13 checks passed
@duriantaco

Copy link
Copy Markdown
Contributor Author

most welcome! just doing my part for an amazing library too :)

@duriantaco
duriantaco deleted the remove-dead-code branch March 23, 2026 05:31
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