Question on mutable default values #7296
function2-llx
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
Some codes in the repository use mutable default value (mostly, default value for
norm
andact
). E.g., in the following example, although a tuple of("instance", {"affine": True})
is immutable, the dict inside the tuple is still mutable.MONAI/monai/networks/nets/basic_unet.py
Lines 178 to 190 in 782c1e6
Using mutable default is usually discouraged (e.g., official documentation). However, most of the time it actually works as expected, maybe it is just a choice of coding style.
Possible solution: change every dict in the default to
MappingProxyType
, but I personally think that this will make code ugly.Beta Was this translation helpful? Give feedback.
All reactions