Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using mutables as default parameters #1142

Merged
merged 7 commits into from Jan 16, 2023

Conversation

santisoler
Copy link
Member

@santisoler santisoler commented Dec 9, 2022

Fix flake8 B006 warnings. Avoid using mutables as default values for
function and methods parameters. Default function parameters are
evaluated only once during function definition. If those default values
are mutable variables it's possible that the function call might change
it, leading to a "new default" value on subsequent function calls.
Use tuples instead of lists and None for dictionaries (the default value
could be defined inside the body through a quick is None check).
Remove B006 from the ignored warnings in Makefile.

This article has good explanations of why using mutable default values is discouraged.

Fix `flake8` `B006` warnings. Avoid using mutables as default values for
function and methods parameters. Default function parameters are
evaluated only once during function definition. If those default values
are mutable variables it's possible that the function call might change
it, leading to a "new default" value on subsequent function calls.
Use tuples instead of lists and None for dictionaries (the default value
could be defined inside the body through a quick `is None` check).
@codecov
Copy link

codecov bot commented Dec 9, 2022

Codecov Report

Merging #1142 (7e5f852) into main (034a5cb) will decrease coverage by 25.98%.
The diff coverage is 38.70%.

❗ Current head 7e5f852 differs from pull request most recent head 1cdb81e. Consider uploading reports for the commit 1cdb81e to get more accurate results

@@             Coverage Diff             @@
##             main    #1142       +/-   ##
===========================================
- Coverage   80.23%   54.25%   -25.99%     
===========================================
  Files         158      158               
  Lines       23012    23036       +24     
===========================================
- Hits        18464    12498     -5966     
- Misses       4548    10538     +5990     
Impacted Files Coverage Δ
...lectromagnetics/natural_source/utils/plot_utils.py 12.23% <ø> (-24.78%) ⬇️
...mPEG/electromagnetics/static/utils/static_utils.py 26.05% <0.00%> (-47.00%) ⬇️
SimPEG/utils/io_utils/io_utils_electromagnetics.py 30.66% <0.00%> (-51.47%) ⬇️
SimPEG/utils/pgi_utils.py 45.41% <0.00%> (-25.87%) ⬇️
...lectromagnetics/natural_source/utils/data_utils.py 9.37% <33.33%> (-1.89%) ⬇️
SimPEG/objective_function.py 88.38% <66.66%> (-4.99%) ⬇️
SimPEG/potential_fields/magnetics/sources.py 100.00% <100.00%> (ø)
SimPEG/utils/plot_utils.py 34.81% <100.00%> (-29.86%) ⬇️
...gnetics/viscous_remanent_magnetization/__init__.py 0.00% <0.00%> (-100.00%) ⬇️
...magnetics/viscous_remanent_magnetization/survey.py 0.00% <0.00%> (-96.97%) ⬇️
... and 82 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jcapriot jcapriot merged commit f9e597a into simpeg:main Jan 16, 2023
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.

None yet

2 participants