dabeaz / curio

Good Curio!
Other
4.01k stars 240 forks source link

Mutable default arguments can cause issues #318

Closed patrickBerry closed 4 years ago

patrickBerry commented 4 years ago

Default arguments that are mutable are bad because they are the same object and one modification can affect the next call and cause unintended behavior. If this was the intended behavior, then at least a comment should be added stating that such behavior was intended.

dabeaz commented 4 years ago

Where are they mutated?

patrickBerry commented 4 years ago

Not sure really. I don't know the codebase well enough to say. I just know that when mutable are used as defaults it can cause bugs down the road. I ran the deepsource.io GitHub plugin on a project of mine that uses Curio (big fan btw) and found this as one of the reports. There were a number of other possible issues reported, but this issue seemed the easiest to report for a pull request.

dabeaz commented 4 years ago

I've looked at the code and the only use of args and kwargs is as a pass-through to a func(*args, **kwargs) call. There is no mutation. As a general rule, I don't like complicating code to account for "what-if" scenarios that never happen.