Skip to content

Commit 41cdc52

Browse files
Add documentation examples for dangerous-default-value. (#6881)
The `good.py` example is taken directly from the Python documentation. Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 0777a0e commit 41cdc52

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def whats_on_the_telly(penguin=[]): # [dangerous-default-value]
2+
penguin.append("property of the zoo")
3+
return penguin
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
1+
With a mutable default value, with each call the default value is modified, i.e.:
2+
3+
.. code-block:: python
4+
5+
whats_on_the_telly() # ["property of the zoo"]
6+
whats_on_the_telly() # ["property of the zoo", "property of the zoo"]
7+
whats_on_the_telly() # ["property of the zoo", "property of the zoo", "property of the zoo"]
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# This is a placeholder for correct code for this message.
1+
def whats_on_the_telly(penguin=None):
2+
if penguin is None:
3+
penguin = []
4+
penguin.append("property of the zoo")
5+
return penguin

0 commit comments

Comments
 (0)