Skip to content

Comments

fix: replace mutable default arguments with None in CNV plot functions#884

Merged
jonbrenas merged 2 commits intomalariagen:masterfrom
PaulaYaniz:fix/mutable-default-args
Feb 21, 2026
Merged

fix: replace mutable default arguments with None in CNV plot functions#884
jonbrenas merged 2 commits intomalariagen:masterfrom
PaulaYaniz:fix/mutable-default-args

Conversation

@PaulaYaniz
Copy link
Contributor

Fixes #787

plot_cnv_hmm_heatmap, plot_cnv_hmm_heatmap_track, and the CNV colorscale in plot_diplotype_clustering_advanced were using a mutable list (cnv_params.colorscale_default) as a default parameter value, which is a dangerous pattern in Python. Replaced with None and added fallback assignment at the start of each function body.

Fixes malariagen#787

plot_cnv_hmm_heatmap, plot_cnv_hmm_heatmap_track, and the CNV colorscale
in plot_diplotype_clustering_advanced were using a mutable list
(cnv_params.colorscale_default) as a default parameter value, which is
a dangerous pattern in Python. Replaced with None and added fallback
assignment at the start of each function body.
Copilot AI review requested due to automatic review settings February 20, 2026 15:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes mutable default argument values in CNV-related plotting APIs by switching the defaults to None and applying the existing cnv_params.colorscale_default inside the function body, addressing the “dangerous-default-value” warning in issue #787.

Changes:

  • Updated plot_diplotype_clustering_advanced() to default cnv_colorscale to None and assign the CNV default colorscale at runtime.
  • Updated plot_cnv_hmm_heatmap_track() and plot_cnv_hmm_heatmap() to default palette to None and assign the CNV default palette at runtime.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
malariagen_data/anoph/dipclust.py Replaces CNV colorscale mutable default arg with None + in-function fallback.
malariagen_data/anoph/cnv_data.py Replaces HMM heatmap palette mutable default args with None + in-function fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jonbrenas
Copy link
Collaborator

Thank you, @PaulaYaniz.

Technically, the problem with mutable lists as parameters only exist if there is a possibility that one of the parameters is going to be modified during the execution. Almost none of the user-facing functions should ever modify their parameters, and certainly none of the plotting functions. It is harder to check, however, so I support your proposed changes.

Copy link
Collaborator

@jonbrenas jonbrenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonbrenas jonbrenas merged commit 2c1964a into malariagen:master Feb 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid using a mutable list or dict as a default value

2 participants