Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[1LP][RFR] Fix dangerous arg value #10274

Merged
merged 1 commit into from
Jul 31, 2020
Merged

[1LP][RFR] Fix dangerous arg value #10274

merged 1 commit into from
Jul 31, 2020

Conversation

jarovo
Copy link
Contributor

@jarovo jarovo commented Jul 29, 2020

Using mutable as default arg value is dangerous as it is evaluated once, when function is being created (module loaded).

This value is preserved between each function calls and when modified, the subsequent calls will use the new state of that default object.

In [2]: def foo(aaa=[]): 
   ...:     aaa.append(3) 
   ...:     return aaa 
   ...:                                                                                                                                                                                       

In [3]: a=foo()                                                                                                                                                                               

In [4]: a                                                                                                                                                                                     
Out[4]: [3]

In [5]: a=foo()                                                                                                                                                                               

In [6]: a                                                                                                                                                                                     
Out[6]: [3, 3]

@jarovo jarovo changed the title Fix dangerous arg value [WIPTEST] Fix dangerous arg value Jul 29, 2020
@jarovo jarovo changed the title [WIPTEST] Fix dangerous arg value [RFR] Fix dangerous arg value Jul 31, 2020
@john-dupuy john-dupuy changed the title [RFR] Fix dangerous arg value [1LP][RFR] Fix dangerous arg value Jul 31, 2020
@mshriver mshriver merged commit c0acc7b into ManageIQ:master Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants