-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Mutable Default Arguments #1561
Comments
Repeated calls will not change default argument if it is none. It's more secure than []. |
@zsef123 @poornagurram I'm not familiar with that code base, but it looks like a bug at a glance. Thanks for catching this! Can you send a PR with a fix? Any other places with unintended mutable defaults? |
Resolved in #1562 |
Just noticed this; a perhaps better fix (at least in the word2vec/keyedvectors/doc2vec cases I've looked closely at) could be to supply empty tuples as the defaults. (They'd thus be armored against any inadvertent future mutations – but no |
@gojomo I'm just following type on original code( |
Same with |
@gojomo @piskvorky Test failed at
Once change from In case of
So I think should cope with using |
Or could move Unsure of issue with use of immutable |
Mutable arguments can have unintended behavior.
like calling repeatedly under function
if call foo 3 times, the result is
[1,1,1]
Python Reference, The Hitchhiker’s Guide to PythonIn summerization/graph.py:175
def add_edge(self, edge, wt=1, label='', attrs=[]):
add_edge
function is used[]
in default argument butadd_node
function is usedNone
.And then check if attrs is None then assigns empty list
I think way of add_node is more secure than add_edge.
How about changing
[]
toNone
?The text was updated successfully, but these errors were encountered: