Closed JayDwee closed 3 years ago
Note: []
(Or {}
) as a default argument is bad style, as contrary to expectation, it doesn't create a new list each call. Instead, default is always the same list, meaning if that list is changed, it changes for all iterations of the call. Better to keep None
as the default, but add
if var is None:
var = []
for each argument. It's a bit verbose, but avoids the issue.
Fixed!
Note:
[]
(Or{}
) as a default argument is bad style, as contrary to expectation, it doesn't create a new list each call. Instead, default is always the same list, meaning if that list is changed, it changes for all iterations of the call. Better to keepNone
as the default, but addif var is None: var = []
for each argument. It's a bit verbose, but avoids the issue.
There's also the pretty good stuff in python :
if not foo:
print("Not foo")
It works with booleans (obviously), integers (0 is falsy), float (0.0), None, empty lists, empty dictionaries', empty strings (""), etc...
(no changes asked ! just to talk about a really cool thing !)
Previously had this issue:
This is a fix for this