-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove default values used as expressions in generate.py
.
#2345
Remove default values used as expressions in generate.py
.
#2345
Conversation
Thansk @h-mayorquin Can you check why tests are failing? It seems related to the change! |
""" """ | ||
assert len(split_ids) > 0, "you need to provide some ids to split" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alejoe91
The error was caused by the fact that np.array(0) behaves as False
. I should know better to not play with the truthiness of containers.
However, as in this case, you actually ask the split_ids to be non-empty I Just made the argument a required one.
I am not sure to like this kind of changes. |
@samuelgarcia |
Hey @h-mayorquin @samuelgarcia sorry for the delay on this! I will open a PR in the second half of next week. I think it is important to remove any mutable default variables due to the unintuitive behaviour of mutable defaults in python. I had a quick look through and it is true that the function does not do any in-place modification of the default arguments, and would probably not cause an bug in this instance at the present time. Nonetheless I think it is important to remove the pattern here and anywhere else it is found in the codebase for the following reasons:
|
Let's go forward with this guys. I think that the majority of us agree that we should follow good practice ;) @h-mayorquin could you solve conflicts? |
Let's try. |
@alejoe91 OK, I fixed them Let's merge because I got conflicts twice already. |
What ?? Here it is little, I do not care so much but I really do not want to this to be the unique rule for all other the place/ For instance here: |
I agree it is less neat but in this I think it is worth the protection it affords, also the alternative pattern gives opportunity for some extra documentation and isolation of kwargs. For example currently
and in the function itself the dict is replaced by I do agree that the existing code is neater than the solution but in this case would advocate the change nonetheless - this really is a very dangerous pattern. Mutable default arguments are a python antipattern and there are many sources warning (a small selection below) against their use:
including this interesting case where the pattern caused failure of a company website launch and 1+ month of heavy bug-fixing! |
This should only be missing durations as @JoeZiminski volunteer himself to do that. See:
#2342