Python collections.abc.MutableSet() Examples
The following are 8
code examples of collections.abc.MutableSet().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
collections.abc
, or try the search function
.
Example #1
Source File: ordered_set.py From pex with Apache License 2.0 | 6 votes |
def discard(self, key): """ Remove an element. Do not raise an exception if absent. The MutableSet mixin uses this to implement the .remove() method, which *does* raise an error when asked to remove a non-existent item. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) """ if key in self: i = self.map[key] del self.items[i] del self.map[key] for k, v in self.map.items(): if v >= i: self.map[k] = v - 1
Example #2
Source File: orderedset.py From ubelt with Apache License 2.0 | 6 votes |
def discard(self, key): """ Remove an element. Do not raise an exception if absent. The MutableSet mixin uses this to implement the .remove() method, which *does* raise an error when asked to remove a non-existent item. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) """ if key in self: i = self.map[key] del self.items[i] del self.map[key] for k, v in self.map.items(): if v >= i: self.map[k] = v - 1
Example #3
Source File: ordered_set.py From rules_pip with MIT License | 6 votes |
def discard(self, key): """ Remove an element. Do not raise an exception if absent. The MutableSet mixin uses this to implement the .remove() method, which *does* raise an error when asked to remove a non-existent item. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) """ if key in self: i = self.map[key] del self.items[i] del self.map[key] for k, v in self.map.items(): if v >= i: self.map[k] = v - 1
Example #4
Source File: ordered_set.py From setuptools with MIT License | 6 votes |
def discard(self, key): """ Remove an element. Do not raise an exception if absent. The MutableSet mixin uses this to implement the .remove() method, which *does* raise an error when asked to remove a non-existent item. Example: >>> oset = OrderedSet([1, 2, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) >>> oset.discard(2) >>> print(oset) OrderedSet([1, 3]) """ if key in self: i = self.map[key] del self.items[i] del self.map[key] for k, v in self.map.items(): if v >= i: self.map[k] = v - 1
Example #5
Source File: collections.py From python-clean-architecture with MIT License | 5 votes |
def discard(self, key): """ Remove an element. Do not raise an exception if absent. The MutableSet mixin uses this to implement the .remove() method, which *does* raise an error when asked to remove a non-existent item. """ if key in self: i = self.items.index(key) del self.items[i] del self.map[key] for k, v in self.map.items(): if v >= i: self.map[k] = v - 1
Example #6
Source File: codepoints.py From xmlschema with MIT License | 5 votes |
def iter_characters(self): return map(chr, self.__iter__()) # # MutableSet's abstract methods implementation
Example #7
Source File: codepoints.py From xmlschema with MIT License | 5 votes |
def discard(self, value): start_cp, end_cp = check_code_point(value) code_points = self._code_points for k in reversed(range(len(code_points))): cp = code_points[k] if isinstance(cp, int): cp = cp, cp + 1 if start_cp >= cp[1]: break elif end_cp >= cp[1]: if start_cp <= cp[0]: del code_points[k] elif start_cp - cp[0] > 1: code_points[k] = cp[0], start_cp else: code_points[k] = cp[0] elif end_cp > cp[0]: if start_cp <= cp[0]: if cp[1] - end_cp > 1: code_points[k] = end_cp, cp[1] else: code_points[k] = cp[1] - 1 else: if cp[1] - end_cp > 1: code_points.insert(k + 1, (end_cp, cp[1])) else: code_points.insert(k + 1, cp[1] - 1) if start_cp - cp[0] > 1: code_points[k] = cp[0], start_cp else: code_points[k] = cp[0] # # MutableSet's mixin methods override
Example #8
Source File: core.py From django-more with BSD 3-Clause "New" or "Revised" License | 4 votes |
def apply(self, attrs=None, kattrs=None, merge=False): """ Apply new attributes or classes to the target """ for attr in attrs: kattrs = kattrs or {} # Treat objects as assigned to their name if hasattr(attr, "__name__"): kattrs[attr.__name__] = attr else: kattrs[attr] = inspect.getattr_static(self.source, attr) for attr, value in kattrs.items(): old_value = inspect.getattr_static(self.target, attr, None) # If callable, preserve old func if callable(value) and callable(old_value): # Prevent duplicate patching if value in patchy_records: continue patchy_records[value] = old_value # Merge collections and classes instead of replacing if merge: if isinstance(old_value, abc.Container): if isinstance(value, abc.Mapping) and isinstance(old_value, abc.MutableMapping): old_value.update(value) logger.info('Merging mapping {mod}.{attr}'.format(mod=self.target.__name__, attr=attr)) elif isinstance(value, abc.Sequence) and isinstance(old_value, abc.MutableSequence): old_value.extend(value) logger.info('Merging sequence {mod}.{attr}'.format(mod=self.target.__name__, attr=attr)) elif isinstance(value, abc.Set) and isinstance(old_value, abc.MutableSet): old_value.update(value) logger.info('Merging set {mod}.{attr}'.format(mod=self.target.__name__, attr=attr)) else: setattr(self.target, attr, value) logger.info("Couldn't merge collection {target}.{attr}, replaced instead".format( target=self.target.__name__, attr=attr)) continue elif isinstance(old_value, type): logger.info('Merging class for {target}.{attr}'.format( target=self.target.__name__, attr=attr)) self.cls(old_value, value).auto() continue logger.info('Setting value {target}.{attr}'.format(target=self.target.__name__, attr=attr)) # Apply patched value setattr(self.target, attr, value)