This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author akira
Recipients akira, josh.r, rhettinger, roy.wellington
Date 2014-07-29.10:54:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1406631276.29.0.331609431288.issue22089@psf.upfronthosting.co.za>
In-reply-to
Content
Set has no __ior__ method but MutableSet has:

  class MySet(MutableSet):
      update = MutableSet.__ior__

Unlike set.__ior__; MutableSet.__ior__ accepts an arbitrary iterable
and therefore MutableSet.update is redundant.

set.__ior__ doesn't accept an arbitrary iterable:

  >>> s = set()
  >>> s.update('ab')
  >>> s |= 'ab'
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: unsupported operand type(s) for |=: 'set' and 'str'
  >>> s |= set('ab')
  >>> s
  {'a', 'b'}

MutableSet.__ior__ does accept an arbitrary iterable:

  from collections.abc import MutableSet
  
  class UpperSet(MutableSet):
      """Like set() but stores items in upper case."""
      def __init__(self, iterable=()):
          self._set = set()
          self |= iterable
      def _key(self, item):
          return item.upper()
      update = MutableSet.__ior__
  
      # implement MutableSet abstract methods
      def __contains__(self, item):
          return self._key(item) in self._set
      def __iter__(self):
          return iter(self._set)
      def __len__(self):
          return len(self._set)
      def add(self, item):
          self._set.add(self._key(item))
      def discard(self, item):
          self._set.discard(self._key(item))
  
Example:

  s = UpperSet('σs')
  assert 'σ' in s and 'Σ' in s and 'S' in s and 'ς' in s and 'ſ' in s
  s.update('dzẞ') # or s |= 'dzẞ'
  assert 'Dz' in s and 'DZ' in s and 'ß' not in s and 'SS' not in s
  s |= 'ß' # or s.update('ß')
  assert s == {'Σ', 'S', 'DZ', 'ẞ', 'SS'}
History
Date User Action Args
2014-07-29 10:54:36akirasetrecipients: + akira, rhettinger, josh.r, roy.wellington
2014-07-29 10:54:36akirasetmessageid: <1406631276.29.0.331609431288.issue22089@psf.upfronthosting.co.za>
2014-07-29 10:54:36akiralinkissue22089 messages
2014-07-29 10:54:35akiracreate