Skip to content

Replace mutable default arguments with None#302

Open
Qinusty wants to merge 1 commit into
keras-rl:masterfrom
Qinusty:fix-mutable-default-arguments
Open

Replace mutable default arguments with None#302
Qinusty wants to merge 1 commit into
keras-rl:masterfrom
Qinusty:fix-mutable-default-arguments

Conversation

@Qinusty

@Qinusty Qinusty commented Mar 13, 2019

Copy link
Copy Markdown

Using mutable types (e.g. [], {}) for default arguments can lead to unexpected behaviour as detailed here.

I have done my best to locate all the occurances within the repository however some may still remain through various searches including =[]):, ={}):, =[],, ={},.

Replacements should follow as such:

# Function with mutable argument as default
def func(self, var=[]):

# Should become
def func(self, var=None):
    if var is None:
        var = []

This fixes #309

@Qinusty Qinusty force-pushed the fix-mutable-default-arguments branch from c1c2caa to 892688c Compare March 13, 2019 16:39
@Qinusty Qinusty force-pushed the fix-mutable-default-arguments branch from 892688c to 35f41ab Compare October 19, 2019 11:08
@Qinusty

Qinusty commented Oct 19, 2019

Copy link
Copy Markdown
Author

Rebased to master.

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.

Use of mutable default arguments throughout project

2 participants