
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
39 lines
985 B
Plaintext
39 lines
985 B
Plaintext
== Why is this an issue?
|
|
|
|
While the assignment of default parameter values is typically a good thing, it can go very wrong very quickly when mutable objects are used. That's because a new instance of the object _is not_ created for each function invocation. Instead, all invocations share the same instance, and the changes made for one caller are made for all!
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
def get_attr_array(obj, arr=[]): # Noncompliant
|
|
props = (name for name in dir(obj) if not name.startswith('_'))
|
|
arr.extend(props) # after only a few calls, this is a big array!
|
|
return arr
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
def get_attr_array(obj, arr):
|
|
props = (name for name in dir(obj) if not name.startswith('_'))
|
|
arr.extend(props)
|
|
return arr
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove the default value of "xxx".
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|