Skip to content

Commit a12841c

Browse files
[3.13] gh-101100: Fix references to the set methods (GH-141857) (GH-142345)
(cherry picked from commit 1d8f3ed) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 90ca216 commit a12841c

File tree

4 files changed

+111
-104
lines changed

4 files changed

+111
-104
lines changed

Doc/c-api/set.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
147147
148148
Return ``1`` if found and removed, ``0`` if not found (no action taken), and ``-1`` if an
149149
error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a
150-
:exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~frozenset.discard`
150+
:exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard`
151151
method, this function does not automatically convert unhashable sets into
152152
temporary frozensets. Raise :exc:`SystemError` if *set* is not an
153153
instance of :class:`set` or its subtype.

Doc/library/stdtypes.rst

Lines changed: 108 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4602,164 +4602,172 @@ The constructors for both classes work the same:
46024602
objects. If *iterable* is not specified, a new empty set is
46034603
returned.
46044604

4605-
Sets can be created by several means:
4605+
Sets can be created by several means:
46064606

4607-
* Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'}``
4608-
* Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'}``
4609-
* Use the type constructor: ``set()``, ``set('foobar')``, ``set(['a', 'b', 'foo'])``
4607+
* Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'}``
4608+
* Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'}``
4609+
* Use the type constructor: ``set()``, ``set('foobar')``, ``set(['a', 'b', 'foo'])``
46104610

4611-
Instances of :class:`set` and :class:`frozenset` provide the following
4612-
operations:
4611+
Instances of :class:`set` and :class:`frozenset` provide the following
4612+
operations:
46134613

4614-
.. describe:: len(s)
4614+
.. describe:: len(s)
46154615

4616-
Return the number of elements in set *s* (cardinality of *s*).
4616+
Return the number of elements in set *s* (cardinality of *s*).
46174617

4618-
.. describe:: x in s
4618+
.. describe:: x in s
46194619

4620-
Test *x* for membership in *s*.
4620+
Test *x* for membership in *s*.
46214621

4622-
.. describe:: x not in s
4622+
.. describe:: x not in s
46234623

4624-
Test *x* for non-membership in *s*.
4624+
Test *x* for non-membership in *s*.
46254625

4626-
.. method:: isdisjoint(other, /)
4626+
.. method:: frozenset.isdisjoint(other, /)
4627+
set.isdisjoint(other, /)
46274628

4628-
Return ``True`` if the set has no elements in common with *other*. Sets are
4629-
disjoint if and only if their intersection is the empty set.
4629+
Return ``True`` if the set has no elements in common with *other*. Sets are
4630+
disjoint if and only if their intersection is the empty set.
46304631

4631-
.. method:: issubset(other, /)
4632-
set <= other
4632+
.. method:: frozenset.issubset(other, /)
4633+
set.issubset(other, /)
4634+
.. describe:: set <= other
46334635

4634-
Test whether every element in the set is in *other*.
4636+
Test whether every element in the set is in *other*.
46354637

4636-
.. method:: set < other
4638+
.. describe:: set < other
46374639

4638-
Test whether the set is a proper subset of *other*, that is,
4639-
``set <= other and set != other``.
4640+
Test whether the set is a proper subset of *other*, that is,
4641+
``set <= other and set != other``.
46404642

4641-
.. method:: issuperset(other, /)
4642-
set >= other
4643+
.. method:: frozenset.issuperset(other, /)
4644+
set.issuperset(other, /)
4645+
.. describe:: set >= other
46434646

4644-
Test whether every element in *other* is in the set.
4647+
Test whether every element in *other* is in the set.
46454648

4646-
.. method:: set > other
4649+
.. describe:: set > other
46474650

4648-
Test whether the set is a proper superset of *other*, that is, ``set >=
4649-
other and set != other``.
4651+
Test whether the set is a proper superset of *other*, that is, ``set >=
4652+
other and set != other``.
46504653

4651-
.. method:: union(*others)
4652-
set | other | ...
4654+
.. method:: frozenset.union(*others)
4655+
set.union(*others)
4656+
.. describe:: set | other | ...
46534657
4654-
Return a new set with elements from the set and all others.
4658+
Return a new set with elements from the set and all others.
46554659

4656-
.. method:: intersection(*others)
4657-
set & other & ...
4660+
.. method:: frozenset.intersection(*others)
4661+
set.intersection(*others)
4662+
.. describe:: set & other & ...
46584663
4659-
Return a new set with elements common to the set and all others.
4664+
Return a new set with elements common to the set and all others.
46604665

4661-
.. method:: difference(*others)
4662-
set - other - ...
4666+
.. method:: frozenset.difference(*others)
4667+
set.difference(*others)
4668+
.. describe:: set - other - ...
46634669
4664-
Return a new set with elements in the set that are not in the others.
4670+
Return a new set with elements in the set that are not in the others.
46654671

4666-
.. method:: symmetric_difference(other, /)
4667-
set ^ other
4672+
.. method:: frozenset.symmetric_difference(other, /)
4673+
set.symmetric_difference(other, /)
4674+
.. describe:: set ^ other
46684675

4669-
Return a new set with elements in either the set or *other* but not both.
4676+
Return a new set with elements in either the set or *other* but not both.
46704677

4671-
.. method:: copy()
4678+
.. method:: frozenset.copy()
4679+
set.copy()
46724680

4673-
Return a shallow copy of the set.
4681+
Return a shallow copy of the set.
46744682

46754683

4676-
Note, the non-operator versions of :meth:`union`, :meth:`intersection`,
4677-
:meth:`difference`, :meth:`symmetric_difference`, :meth:`issubset`, and
4678-
:meth:`issuperset` methods will accept any iterable as an argument. In
4679-
contrast, their operator based counterparts require their arguments to be
4680-
sets. This precludes error-prone constructions like ``set('abc') & 'cbs'``
4681-
in favor of the more readable ``set('abc').intersection('cbs')``.
4684+
Note, the non-operator versions of :meth:`~frozenset.union`,
4685+
:meth:`~frozenset.intersection`, :meth:`~frozenset.difference`, :meth:`~frozenset.symmetric_difference`, :meth:`~frozenset.issubset`, and
4686+
:meth:`~frozenset.issuperset` methods will accept any iterable as an argument. In
4687+
contrast, their operator based counterparts require their arguments to be
4688+
sets. This precludes error-prone constructions like ``set('abc') & 'cbs'``
4689+
in favor of the more readable ``set('abc').intersection('cbs')``.
46824690

4683-
Both :class:`set` and :class:`frozenset` support set to set comparisons. Two
4684-
sets are equal if and only if every element of each set is contained in the
4685-
other (each is a subset of the other). A set is less than another set if and
4686-
only if the first set is a proper subset of the second set (is a subset, but
4687-
is not equal). A set is greater than another set if and only if the first set
4688-
is a proper superset of the second set (is a superset, but is not equal).
4691+
Both :class:`set` and :class:`frozenset` support set to set comparisons. Two
4692+
sets are equal if and only if every element of each set is contained in the
4693+
other (each is a subset of the other). A set is less than another set if and
4694+
only if the first set is a proper subset of the second set (is a subset, but
4695+
is not equal). A set is greater than another set if and only if the first set
4696+
is a proper superset of the second set (is a superset, but is not equal).
46894697

4690-
Instances of :class:`set` are compared to instances of :class:`frozenset`
4691-
based on their members. For example, ``set('abc') == frozenset('abc')``
4692-
returns ``True`` and so does ``set('abc') in set([frozenset('abc')])``.
4698+
Instances of :class:`set` are compared to instances of :class:`frozenset`
4699+
based on their members. For example, ``set('abc') == frozenset('abc')``
4700+
returns ``True`` and so does ``set('abc') in set([frozenset('abc')])``.
46934701

4694-
The subset and equality comparisons do not generalize to a total ordering
4695-
function. For example, any two nonempty disjoint sets are not equal and are not
4696-
subsets of each other, so *all* of the following return ``False``: ``a<b``,
4697-
``a==b``, or ``a>b``.
4702+
The subset and equality comparisons do not generalize to a total ordering
4703+
function. For example, any two nonempty disjoint sets are not equal and are not
4704+
subsets of each other, so *all* of the following return ``False``: ``a<b``,
4705+
``a==b``, or ``a>b``.
46984706

4699-
Since sets only define partial ordering (subset relationships), the output of
4700-
the :meth:`list.sort` method is undefined for lists of sets.
4707+
Since sets only define partial ordering (subset relationships), the output of
4708+
the :meth:`list.sort` method is undefined for lists of sets.
47014709

4702-
Set elements, like dictionary keys, must be :term:`hashable`.
4710+
Set elements, like dictionary keys, must be :term:`hashable`.
47034711

4704-
Binary operations that mix :class:`set` instances with :class:`frozenset`
4705-
return the type of the first operand. For example: ``frozenset('ab') |
4706-
set('bc')`` returns an instance of :class:`frozenset`.
4712+
Binary operations that mix :class:`set` instances with :class:`frozenset`
4713+
return the type of the first operand. For example: ``frozenset('ab') |
4714+
set('bc')`` returns an instance of :class:`frozenset`.
47074715

4708-
The following table lists operations available for :class:`set` that do not
4709-
apply to immutable instances of :class:`frozenset`:
4716+
The following table lists operations available for :class:`set` that do not
4717+
apply to immutable instances of :class:`frozenset`:
47104718

4711-
.. method:: update(*others)
4712-
set |= other | ...
4719+
.. method:: set.update(*others)
4720+
.. describe:: set |= other | ...
47134721

4714-
Update the set, adding elements from all others.
4722+
Update the set, adding elements from all others.
47154723

4716-
.. method:: intersection_update(*others)
4717-
set &= other & ...
4724+
.. method:: set.intersection_update(*others)
4725+
.. describe:: set &= other & ...
47184726

4719-
Update the set, keeping only elements found in it and all others.
4727+
Update the set, keeping only elements found in it and all others.
47204728

4721-
.. method:: difference_update(*others)
4722-
set -= other | ...
4729+
.. method:: set.difference_update(*others)
4730+
.. describe:: set -= other | ...
47234731

4724-
Update the set, removing elements found in others.
4732+
Update the set, removing elements found in others.
47254733

4726-
.. method:: symmetric_difference_update(other, /)
4727-
set ^= other
4734+
.. method:: set.symmetric_difference_update(other, /)
4735+
.. describe:: set ^= other
47284736

4729-
Update the set, keeping only elements found in either set, but not in both.
4737+
Update the set, keeping only elements found in either set, but not in both.
47304738

4731-
.. method:: add(elem, /)
4739+
.. method:: set.add(elem, /)
47324740

4733-
Add element *elem* to the set.
4741+
Add element *elem* to the set.
47344742

4735-
.. method:: remove(elem, /)
4743+
.. method:: set.remove(elem, /)
47364744

4737-
Remove element *elem* from the set. Raises :exc:`KeyError` if *elem* is
4738-
not contained in the set.
4745+
Remove element *elem* from the set. Raises :exc:`KeyError` if *elem* is
4746+
not contained in the set.
47394747

4740-
.. method:: discard(elem, /)
4748+
.. method:: set.discard(elem, /)
47414749

4742-
Remove element *elem* from the set if it is present.
4750+
Remove element *elem* from the set if it is present.
47434751

4744-
.. method:: pop()
4752+
.. method:: set.pop()
47454753

4746-
Remove and return an arbitrary element from the set. Raises
4747-
:exc:`KeyError` if the set is empty.
4754+
Remove and return an arbitrary element from the set. Raises
4755+
:exc:`KeyError` if the set is empty.
47484756

4749-
.. method:: clear()
4757+
.. method:: set.clear()
47504758

4751-
Remove all elements from the set.
4759+
Remove all elements from the set.
47524760

47534761

4754-
Note, the non-operator versions of the :meth:`update`,
4755-
:meth:`intersection_update`, :meth:`difference_update`, and
4756-
:meth:`symmetric_difference_update` methods will accept any iterable as an
4757-
argument.
4762+
Note, the non-operator versions of the :meth:`~set.update`,
4763+
:meth:`~set.intersection_update`, :meth:`~set.difference_update`, and
4764+
:meth:`~set.symmetric_difference_update` methods will accept any iterable as an
4765+
argument.
47584766

4759-
Note, the *elem* argument to the :meth:`~object.__contains__`,
4760-
:meth:`remove`, and
4761-
:meth:`discard` methods may be a set. To support searching for an equivalent
4762-
frozenset, a temporary one is created from *elem*.
4767+
Note, the *elem* argument to the :meth:`~object.__contains__`,
4768+
:meth:`~set.remove`, and
4769+
:meth:`~set.discard` methods may be a set. To support searching for an equivalent
4770+
frozenset, a temporary one is created from *elem*.
47634771

47644772

47654773
.. _typesmapping:

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Doc/library/pyexpat.rst
3030
Doc/library/select.rst
3131
Doc/library/socket.rst
3232
Doc/library/ssl.rst
33-
Doc/library/stdtypes.rst
3433
Doc/library/subprocess.rst
3534
Doc/library/termios.rst
3635
Doc/library/test.rst

Doc/whatsnew/2.3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Here's a simple example::
6666
The union and intersection of sets can be computed with the :meth:`~frozenset.union` and
6767
:meth:`~frozenset.intersection` methods; an alternative notation uses the bitwise operators
6868
``&`` and ``|``. Mutable sets also have in-place versions of these methods,
69-
:meth:`!union_update` and :meth:`~frozenset.intersection_update`. ::
69+
:meth:`!union_update` and :meth:`~set.intersection_update`. ::
7070

7171
>>> S1 = sets.Set([1,2,3])
7272
>>> S2 = sets.Set([4,5,6])
@@ -87,7 +87,7 @@ It's also possible to take the symmetric difference of two sets. This is the
8787
set of all elements in the union that aren't in the intersection. Another way
8888
of putting it is that the symmetric difference contains all elements that are in
8989
exactly one set. Again, there's an alternative notation (``^``), and an
90-
in-place version with the ungainly name :meth:`~frozenset.symmetric_difference_update`. ::
90+
in-place version with the ungainly name :meth:`~set.symmetric_difference_update`. ::
9191

9292
>>> S1 = sets.Set([1,2,3,4])
9393
>>> S2 = sets.Set([3,4,5,6])

0 commit comments

Comments
 (0)