Skip to content

Commit

Permalink
Remove mutable default arg in function example (#944)
Browse files Browse the repository at this point in the history
* Remove mutable default arg in function example

Removed mutable default arg, replaced with `None`.
https://docs.quantifiedcode.com/python-anti-patterns/correctness/mutable_default_value_as_argument.html

Replaced `dict()` with `{}`.
https://stackoverflow.com/questions/8424942/creating-a-new-dictionary-in-python

* Wrong import

* Undo last commit

My bad.

Co-authored-by: Hynek Schlawack <hs@ox.cx>
  • Loading branch information
MicaelJarniac and hynek committed Apr 7, 2022
1 parent f376db2 commit 2afbcb2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/extending.rst
Expand Up @@ -176,10 +176,10 @@ Here are some tips for effective use of metadata:
>>>
>>> def typed(
... cls, default=NOTHING, validator=None, repr=True,
... eq=True, order=None, hash=None, init=True, metadata={},
... eq=True, order=None, hash=None, init=True, metadata=None,
... converter=None
... ):
... metadata = dict() if not metadata else metadata
... metadata = metadata or {}
... metadata[MY_TYPE_METADATA] = cls
... return field(
... default=default, validator=validator, repr=repr,
Expand Down

0 comments on commit 2afbcb2

Please sign in to comment.