當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。