当前位置: 首页>>代码示例>>Python>>正文


Python collections.MutableSet方法代码示例

本文整理汇总了Python中collections.MutableSet方法的典型用法代码示例。如果您正苦于以下问题:Python collections.MutableSet方法的具体用法?Python collections.MutableSet怎么用?Python collections.MutableSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections的用法示例。


在下文中一共展示了collections.MutableSet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: discard

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
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 
开发者ID:pantsbuild,项目名称:pex,代码行数:25,代码来源:ordered_set.py

示例2: remove_key

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
def remove_key(self, key):
        # The parts of the ConfigSection that might contain "key"
        trackers = [self.validation_methods,
                    self._destinations,
                    self._restricted,
                    self._required_keys,
                    self.defaults,
                    self._values,
                    self._unvalidated_keys,
                    ]
        for tracker in trackers:
            if key in tracker:
                if isinstance(tracker, collections.MutableMapping):
                    del tracker[key]
                elif isinstance(tracker, collections.MutableSequence):
                    tracker.remove(key)
                elif isinstance(tracker, collections.MutableSet):
                    tracker.discard(key) 
开发者ID:candlepin,项目名称:virt-who,代码行数:20,代码来源:config.py

示例3: modifies_known_mutable

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
def modifies_known_mutable(obj, attr):
    """This function checks if an attribute on a builtin mutable object
    (list, dict, set or deque) would modify it if called.  It also supports
    the "user"-versions of the objects (`sets.Set`, `UserDict.*` etc.) and
    with Python 2.6 onwards the abstract base classes `MutableSet`,
    `MutableMapping`, and `MutableSequence`.

    >>> modifies_known_mutable({}, "clear")
    True
    >>> modifies_known_mutable({}, "keys")
    False
    >>> modifies_known_mutable([], "append")
    True
    >>> modifies_known_mutable([], "index")
    False

    If called with an unsupported object (such as unicode) `False` is
    returned.

    >>> modifies_known_mutable("foo", "upper")
    False
    """
    for typespec, unsafe in _mutable_spec:
        if isinstance(obj, typespec):
            return attr in unsafe
    return False 
开发者ID:remg427,项目名称:misp42splunk,代码行数:28,代码来源:sandbox.py

示例4: test_MutableSet

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
def test_MutableSet(self):
        self.assertIsInstance(set(), MutableSet)
        self.assertTrue(issubclass(set, MutableSet))
        self.assertNotIsInstance(frozenset(), MutableSet)
        self.assertFalse(issubclass(frozenset, MutableSet))
        self.validate_abstract_methods(MutableSet, '__contains__', '__iter__', '__len__',
            'add', 'discard') 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:9,代码来源:test_collections.py

示例5: test_issue_5647

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
def test_issue_5647(self):
        # MutableSet.__iand__ mutated the set during iteration
        s = WithSet('abcd')
        s &= WithSet('cdef')            # This used to fail
        self.assertEqual(set(s), set('cd')) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:7,代码来源:test_collections.py

示例6: test_issue_4920

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
def test_issue_4920(self):
        # MutableSet.pop() method did not work
        class MySet(collections.MutableSet):
            __slots__=['__s']
            def __init__(self,items=None):
                if items is None:
                    items=[]
                self.__s=set(items)
            def __contains__(self,v):
                return v in self.__s
            def __iter__(self):
                return iter(self.__s)
            def __len__(self):
                return len(self.__s)
            def add(self,v):
                result=v not in self.__s
                self.__s.add(v)
                return result
            def discard(self,v):
                result=v in self.__s
                self.__s.discard(v)
                return result
            def __repr__(self):
                return "MySet(%s)" % repr(list(self))
        s = MySet([5,43,2,1])
        self.assertEqual(s.pop(), 1) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:28,代码来源:test_collections.py

示例7: is_mutable

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
def is_mutable(obj):
    return isinstance(obj, (collections.MutableSequence,
                            collections.MutableSet,
                            collections.MutableMapping)) 
开发者ID:openstack,项目名称:yaql,代码行数:6,代码来源:utils.py

示例8: clear

# 需要导入模块: import collections [as 别名]
# 或者: from collections import MutableSet [as 别名]
def clear(self):
        self._items.clear()


# From this point on, only tests.
# Perhaps there are more test cases than really required,
# but the MutableSet ABC isn't tested very much in the
# standard regression tests. 
开发者ID:ActiveState,项目名称:code,代码行数:10,代码来源:recipe-576932.py


注:本文中的collections.MutableSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。