@@ -15,8 +15,9 @@ Abstract
1515
1616Add ``list.discard(x) ``, which removes the first item equal to *x * if one
1717is present and does nothing otherwise, returning whether an item was
18- removed. It is the non-raising counterpart to :meth: `list.remove `, as
19- :meth: `set.discard ` is to :meth: `set.remove `.
18+ removed. It is the non-raising counterpart to :meth: `list.remove `, which
19+ currently has none. The name is taken from :meth: `set.discard `, which
20+ already means "remove if present" in Python.
2021
2122
2223Motivation
@@ -79,16 +80,15 @@ method for consistency.
7980Rationale
8081=========
8182
82- The name follows the ``remove() `` / ``discard() `` distinction already
83- made by ``set ``, where ``discard() `` is the variant that tolerates a
84- missing item. It has been raised that after ``s.discard(x) `` the test
85- ``x not in s `` holds, while after ``lst.discard(x) `` it need not if *x *
86- appears more than once. This is a real difference. ``discard() ``
87- deliberately shares the search and removal semantics of :meth: `list.remove `
88- rather than those of :meth: `set.discard `, and the documentation for
89- ``list.discard() `` in the reference implementation states this explicitly.
90- The name remains the least surprising choice as users who know
91- sets can apply that knowledge directly.
83+ Symmetry with :class: `set ` is not the goal. The motivation is the missing
84+ non-raising form of :meth: `list.remove `. :class: `set ` only supplies the name,
85+ since :meth: `set.discard ` already means "remove if present" in Python.
86+
87+ It has been raised that after ``s.discard(x) `` the test ``x not in s ``
88+ holds, while after ``lst.discard(x) `` it need not if *x * appears more than
89+ once. That is a property of sets, not of ``discard() ``, and
90+ :meth: `list.remove ` has the same behaviour today. ``discard() `` follows
91+ ``remove() `` here, and its will documentation clearly say so.
9292
9393Unlike :meth: `set.discard `, which returns ``None ``, a bool is returned. This
9494costs nothing, since the implementation already knows the outcome, and lets
0 commit comments