def field_names(self) -> KeysView: """ Return read-only key view with the names of all the defined fields for the item """ if is_scrapy_item(self.item): return KeysView(self.item.fields) elif is_dataclass_instance(self.item): return KeysView(self._fields_dict) elif is_attrs_instance(self.item): return KeysView(self._fields_dict) else: return KeysView(self.item)
def test_views(bi, data): """Optimized view APIs should be equivalent to using the corresponding MappingViews from :mod:`collections.abc`.""" for check, oracle in (bi.keys(), KeysView(bi)), (bi.values(), ValuesView(bi)), (bi.items(), ItemsView(bi)): # 0-arity methods: __len__, __iter__ assert check.__len__() == oracle.__len__() assert list(check.__iter__()) == list(oracle.__iter__()) # 1-arity methods: __contains__ arg = data.draw( st.PAIRS if isinstance(oracle, ItemsView) else st.ATOMS) assert check.__contains__(arg) == oracle.__contains__(arg) # Methods of set-like views if isinstance(oracle, ValuesView): continue arg = data.draw(st.KEYSVIEW_SET_OP_ARGS if isinstance( oracle, KeysView) else st.ITEMSVIEW_SET_OP_ARGS) for so in _SET_OPS: try: expect = so(oracle, arg) except TypeError: with pytest.raises(TypeError): so(check, arg) else: check_ = so(check, arg) assert check_ == expect, (check, so, arg) try: expect = so(arg, oracle) except TypeError: with pytest.raises(TypeError): so(arg, check) else: check_ = so(arg, check) assert check_ == expect, (check, so, arg)
def _update_array_cache(self): # extract all features from self._levels self._depth = next(self._levels.depths()) # store both NP array of labels, as well as KeysView of hashable tuples self._labels = self._levels.get_labels() # note: this does not retain order in 3.5 self._keys = KeysView._from_iterable(array2d_to_tuples(self._labels)) # if we get labels, faster to get that length self._length = len(self._labels) #self._levels.__len__() self._recache = False
def keys(self): """Set-like object providing a view of index keys. >>> index = Index() >>> index.update({'a': 1, 'b': 2, 'c': 3}) >>> keys_view = index.keys() >>> 'b' in keys_view True :return: keys view """ return KeysView(self)
def viewkeys(self): """Set-like object providing a view of index keys. >>> index = Index('/tmp/diskcache/index') >>> index.clear() >>> index.update({'a': 1, 'b': 2, 'c': 3}) >>> keys_view = index.viewkeys() >>> 'b' in keys_view True :return: keys view """ return KeysView(self)
def keys(self): """ Get a view object on member names """ return KeysView(self)
def field_names(self) -> KeysView: return KeysView(self._fields_dict)
def namespace_keys(self, namespace, keep_namespace=False): return KeysView( redis_key_to_key(k).key for k in self.scan_namespace_iter(namespace))
def keys(self): return KeysView(self)
def viewkeys(self): "OMD.viewkeys() -> a set-like object providing a view on OMD's keys" return KeysView(self)
def variables(self) -> Collection: return KeysView(self._adj)
def keys(self, order=None): """Return a KeysView in the given order, or the instance's ``order``, or the class' ``default_order``""" return KeysView(self._to_ordered_dict(order or self.order))
def _abc_keysview_register(view_cls): KeysView.register(view_cls)
def keys(self, fallback=True): # pylint: disable=arguments-differ return KeysView(self if fallback else self._without_fallback())
def breakpoints(self): return KeysView(self._breakpoints)
def keys(self): "D.keys() -> a set-like object providing a view on D's keys" return KeysView(self)
def variables(self): """The variables of the binary quadratic model.""" return KeysView(self.linear)
def keys(self, max_len: Optional[int] = None) -> Iterator: # type: ignore return Iterator(KeysView(self), max_len=max_len)
assert theEmptyMapping is EmptyMapping() assert theEmptySet is EmptySet() assert theEmptySequence is EmptySequence() assert theEmptyThree is EmptyThree() if 1: #tmp assert not issubclass(EmptyMapping, Mapping) #MappingView.register(EmptyMapping) KeysView.register(EmptySet) ItemsView.register(EmptySet) ValuesView.register(EmptyCollection) assert issubclass(EmptySet, KeysView) assert issubclass(EmptySet, ItemsView) assert issubclass(EmptySet, Set) assert issubclass(EmptySet, MappingView) assert issubclass(EmptyCollection, ValuesView) assert issubclass(EmptyCollection, Collection) assert issubclass(EmptyCollection, MappingView) Mapping.register(EmptyMapping) Set.register(EmptySet) Sequence.register(EmptySequence)
def namespace_keys(self, namespace): filtered = filter(lambda k: k.namespace == namespace, self) return KeysView(k.key for k in filtered)
def field_names(self) -> KeysView: return KeysView(self.item.fields)
def keys(self): return KeysView(self._names)
def keys(self): from collections.abc import KeysView return KeysView(self)