You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use of mutable objects for function argument default values in python is usually unintentional and bug-prone. Example:
def myfunc(firstarg, secondarg=[the list in the above example will be a single object persistent across all function calls, so modification affects future calls to the function.
We should clean these up in our codebase. Here are the places where it appears lists and dictionaries are used in such a way:
trunk/continuousbuild/PyRSS2Gen.py because it's 3rd-party code not part of the actual seattle codebase and changing it would probably risk adding bugs.
trunk/autograder/emulab/sshxmlrpc.py because it's 3rd-party code and there doesn't appear to be a bug in the usage (the list is never modified).
We also need to add a mention of this to the style guide.
I'm CC'ing people who I think are the current maintainers of various of the above files so they can jump in and fix them.
Even if the usages aren't buggy, we should change the above code to avoid the risk that someone could later modify the code and make it buggy. That is, we should fix using mutable objects in this way even if there is no bug currently. If there turns out to be a really good reason for the usage, it should be commented (along with a reminder of the risk of using the mutable object).
The text was updated successfully, but these errors were encountered:
Reassigning to cemeyer because I don't think there are any more in the list that I maintain. Feel free to reassign to armon if you finish updating the ones you maintain first.
The use of mutable objects for function argument default values in python is usually unintentional and bug-prone. Example:
trunk/seattlelib/deserialize.repy:def deserialize_removeObjects(strIn, partitions=:
The above list intentionally leaves out:
trunk/continuousbuild/PyRSS2Gen.py
because it's 3rd-party code not part of the actual seattle codebase and changing it would probably risk adding bugs.trunk/autograder/emulab/sshxmlrpc.py
because it's 3rd-party code and there doesn't appear to be a bug in the usage (the list is never modified).We also need to add a mention of this to the style guide.
I'm CC'ing people who I think are the current maintainers of various of the above files so they can jump in and fix them.
Even if the usages aren't buggy, we should change the above code to avoid the risk that someone could later modify the code and make it buggy. That is, we should fix using mutable objects in this way even if there is no bug currently. If there turns out to be a really good reason for the usage, it should be commented (along with a reminder of the risk of using the mutable object).
The text was updated successfully, but these errors were encountered: