Python operator.is_() Examples
The following are 30
code examples of operator.is_().
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
operator
, or try the search function
.
Example #1
Source File: test_bool.py From ironpython2 with Apache License 2.0 | 7 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) with test_support.check_py3k_warnings(): self.assertIs(operator.isCallable(0), False) self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.isSequenceType(0), False) self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.isMappingType(1), False) self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)
Example #2
Source File: persistence.py From jbox with MIT License | 6 votes |
def _validate_query_state(self): for attr, methname, notset, op in ( ('_limit', 'limit()', None, operator.is_), ('_offset', 'offset()', None, operator.is_), ('_order_by', 'order_by()', False, operator.is_), ('_group_by', 'group_by()', False, operator.is_), ('_distinct', 'distinct()', False, operator.is_), ( '_from_obj', 'join(), outerjoin(), select_from(), or from_self()', (), operator.eq) ): if not op(getattr(self.query, attr), notset): raise sa_exc.InvalidRequestError( "Can't call Query.update() or Query.delete() " "when %s has been called" % (methname, ) )
Example #3
Source File: test_bool.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) with test_support.check_py3k_warnings(): self.assertIs(operator.isCallable(0), False) self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.isSequenceType(0), False) self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.isMappingType(1), False) self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)
Example #4
Source File: persistence.py From android_universal with MIT License | 6 votes |
def _validate_query_state(self): for attr, methname, notset, op in ( ('_limit', 'limit()', None, operator.is_), ('_offset', 'offset()', None, operator.is_), ('_order_by', 'order_by()', False, operator.is_), ('_group_by', 'group_by()', False, operator.is_), ('_distinct', 'distinct()', False, operator.is_), ( '_from_obj', 'join(), outerjoin(), select_from(), or from_self()', (), operator.eq) ): if not op(getattr(self.query, attr), notset): raise sa_exc.InvalidRequestError( "Can't call Query.update() or Query.delete() " "when %s has been called" % (methname, ) )
Example #5
Source File: persistence.py From jarvis with GNU General Public License v2.0 | 6 votes |
def _validate_query_state(self): for attr, methname, notset, op in ( ('_limit', 'limit()', None, operator.is_), ('_offset', 'offset()', None, operator.is_), ('_order_by', 'order_by()', False, operator.is_), ('_group_by', 'group_by()', False, operator.is_), ('_distinct', 'distinct()', False, operator.is_), ( '_from_obj', 'join(), outerjoin(), select_from(), or from_self()', (), operator.eq) ): if not op(getattr(self.query, attr), notset): raise sa_exc.InvalidRequestError( "Can't call Query.update() or Query.delete() " "when %s has been called" % (methname, ) )
Example #6
Source File: test_bool.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) with test_support.check_py3k_warnings(): self.assertIs(operator.isCallable(0), False) self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.isSequenceType(0), False) self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.isMappingType(1), False) self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)
Example #7
Source File: query.py From sqlalchemy with MIT License | 6 votes |
def _validate_query_state(self): for attr, methname, notset, op in ( ("_limit_clause", "limit()", None, operator.is_), ("_offset_clause", "offset()", None, operator.is_), ("_order_by_clauses", "order_by()", (), operator.eq), ("_group_by_clauses", "group_by()", (), operator.eq), ("_distinct", "distinct()", False, operator.is_), ( "_from_obj", "join(), outerjoin(), select_from(), or from_self()", (), operator.eq, ), ( "_legacy_setup_joins", "join(), outerjoin(), select_from(), or from_self()", (), operator.eq, ), ): if not op(getattr(self.query, attr), notset): raise sa_exc.InvalidRequestError( "Can't call Query.update() or Query.delete() " "when %s has been called" % (methname,) )
Example #8
Source File: expressions.py From PeekabooAV with GNU General Public License v3.0 | 6 votes |
def __init__(self, tokens): super().__init__(tokens) self.operator_map = { "<": operator.lt, "<=": operator.le, ">": operator.gt, ">=": operator.ge, "==": operator.eq, "!=": operator.ne, "in": EvalLogic.in_, "not in": EvalLogic.not_in, "is": operator.is_, "is not": operator.is_not, "isdisjoint": lambda a, b: a.isdisjoint(b), "and": operator.and_, "or": operator.or_, }
Example #9
Source File: persistence.py From pyRevit with GNU General Public License v3.0 | 6 votes |
def _validate_query_state(self): for attr, methname, notset, op in ( ('_limit', 'limit()', None, operator.is_), ('_offset', 'offset()', None, operator.is_), ('_order_by', 'order_by()', False, operator.is_), ('_group_by', 'group_by()', False, operator.is_), ('_distinct', 'distinct()', False, operator.is_), ( '_from_obj', 'join(), outerjoin(), select_from(), or from_self()', (), operator.eq) ): if not op(getattr(self.query, attr), notset): raise sa_exc.InvalidRequestError( "Can't call Query.update() or Query.delete() " "when %s has been called" % (methname, ) )
Example #10
Source File: persistence.py From planespotter with MIT License | 6 votes |
def _validate_query_state(self): for attr, methname, notset, op in ( ('_limit', 'limit()', None, operator.is_), ('_offset', 'offset()', None, operator.is_), ('_order_by', 'order_by()', False, operator.is_), ('_group_by', 'group_by()', False, operator.is_), ('_distinct', 'distinct()', False, operator.is_), ( '_from_obj', 'join(), outerjoin(), select_from(), or from_self()', (), operator.eq) ): if not op(getattr(self.query, attr), notset): raise sa_exc.InvalidRequestError( "Can't call Query.update() or Query.delete() " "when %s has been called" % (methname, ) )
Example #11
Source File: macro_is.py From myia with MIT License | 6 votes |
def is_(info, a, b): """Implement the is operator.""" anode, bnode = info.nodes() at = (await a.get()).xtype() bt = (await b.get()).xtype() if at is Nil or bt is Nil: return Constant(at is bt) elif at is NotImplementedType or bt is NotImplementedType: return Constant(at is bt) elif at is Bool and bt is Bool: return info.graph.apply(P.bool_eq, anode, bnode) elif at is Bool or bt is Bool: return Constant(False) else: raise MyiaTypeError( f'The operator "is" is only implemented for booleans ' + f"and singletons such as None or NotImplemented." )
Example #12
Source File: persistence.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _validate_query_state(self): for attr, methname, notset, op in ( ('_limit', 'limit()', None, operator.is_), ('_offset', 'offset()', None, operator.is_), ('_order_by', 'order_by()', False, operator.is_), ('_group_by', 'group_by()', False, operator.is_), ('_distinct', 'distinct()', False, operator.is_), ( '_from_obj', 'join(), outerjoin(), select_from(), or from_self()', (), operator.eq) ): if not op(getattr(self.query, attr), notset): raise sa_exc.InvalidRequestError( "Can't call Query.update() or Query.delete() " "when %s has been called" % (methname, ) )
Example #13
Source File: transformation_utils.py From federated with Apache License 2.0 | 6 votes |
def get_all_payloads_with_value(self, value, equal_fn=None): """Returns all the payloads whose `value` attribute is equal to `value`. Args: value: The value to test. equal_fn: The optional function to use to determine equality, if `None` is specified `operator.is_` is used. """ payloads = [] if equal_fn is None: equal_fn = operator.is_ comp = typing.cast(SequentialBindingNode, self.active_node) while comp.parent is not None or comp.older_sibling is not None: if comp.payload.value is not None and equal_fn(value, comp.payload.value): payloads.append(comp.payload) if comp.older_sibling is not None: comp = comp.older_sibling elif comp.parent is not None: comp = comp.parent return payloads
Example #14
Source File: __init__.py From aireamhan with MIT License | 6 votes |
def add_globals(self): "Add some Scheme standard procedures." import math, cmath, operator as op from functools import reduce self.update(vars(math)) self.update(vars(cmath)) self.update({ '+':op.add, '-':op.sub, '*':op.mul, '/':op.itruediv, 'níl':op.not_, 'agus':op.and_, '>':op.gt, '<':op.lt, '>=':op.ge, '<=':op.le, '=':op.eq, 'mod':op.mod, 'frmh':cmath.sqrt, 'dearbhluach':abs, 'uas':max, 'íos':min, 'cothrom_le?':op.eq, 'ionann?':op.is_, 'fad':len, 'cons':cons, 'ceann':lambda x:x[0], 'tóin':lambda x:x[1:], 'iarcheangail':op.add, 'liosta':lambda *x:list(x), 'liosta?': lambda x:isa(x,list), 'folamh?':lambda x: x == [], 'adamh?':lambda x: not((isa(x, list)) or (x == None)), 'boole?':lambda x: isa(x, bool), 'scag':lambda f, x: list(filter(f, x)), 'cuir_le':lambda proc,l: proc(*l), 'mapáil':lambda p, x: list(map(p, x)), 'lódáil':lambda fn: load(fn), 'léigh':lambda f: f.read(), 'oscail_comhad_ionchuir':open,'dún_comhad_ionchuir':lambda p: p.file.close(), 'oscail_comhad_aschur':lambda f:open(f,'w'), 'dún_comhad_aschur':lambda p: p.close(), 'dac?':lambda x:x is eof_object, 'luacháil':lambda x: evaluate(x), 'scríobh':lambda x,port=sys.stdout:port.write(to_string(x) + '\n')}) return self
Example #15
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_is(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.failUnlessRaises(TypeError, operator.is_) self.failUnless(operator.is_(a, b)) self.failIf(operator.is_(a,c))
Example #16
Source File: conftest.py From twitter-stock-recommendation with MIT License | 5 votes |
def na_cmp(): """Binary operator for comparing NA values. Should return a function of two arguments that returns True if both arguments are (scalar) NA for your type. By default, uses ``operator.is_`` """ return operator.is_
Example #17
Source File: conftest.py From recruit with Apache License 2.0 | 5 votes |
def na_cmp(): """Binary operator for comparing NA values. Should return a function of two arguments that returns True if both arguments are (scalar) NA for your type. By default, uses ``operator.is_`` """ return operator.is_
Example #18
Source File: test_operator.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_is(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.failUnlessRaises(TypeError, operator.is_) self.failUnless(operator.is_(a, b)) self.failIf(operator.is_(a,c))
Example #19
Source File: test_operator.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_is(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_) self.assertTrue(operator.is_(a, b)) self.assertFalse(operator.is_(a,c))
Example #20
Source File: conftest.py From coffeegrindsize with MIT License | 5 votes |
def na_cmp(): """Binary operator for comparing NA values. Should return a function of two arguments that returns True if both arguments are (scalar) NA for your type. By default, uses ``operator.is_`` """ return operator.is_
Example #21
Source File: conftest.py From vnpy_crypto with MIT License | 5 votes |
def na_cmp(): """Binary operator for comparing NA values. Should return a function of two arguments that returns True if both arguments are (scalar) NA for your type. By default, uses ``operator.is_`` """ return operator.is_
Example #22
Source File: test_operator.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_is(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.failUnlessRaises(TypeError, operator.is_) self.failUnless(operator.is_(a, b)) self.failIf(operator.is_(a,c))
Example #23
Source File: test_operator.py From BinderFilter with MIT License | 5 votes |
def test_is(self): a = b = 'xyzpdq' c = a[:3] + b[3:] self.assertRaises(TypeError, operator.is_) self.assertTrue(operator.is_(a, b)) self.assertFalse(operator.is_(a,c))
Example #24
Source File: test_bool.py From BinderFilter with MIT License | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) with test_support.check_py3k_warnings(): self.assertIs(operator.isCallable(0), False) self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.isSequenceType(0), False) self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.isMappingType(1), False) self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)
Example #25
Source File: test_bool.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) self.assertIs(operator.isCallable(0), False) self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.isSequenceType(0), False) self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.isMappingType(1), False) self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)
Example #26
Source File: conftest.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def na_cmp(): """Binary operator for comparing NA values. Should return a function of two arguments that returns True if both arguments are (scalar) NA for your type. By default, uses ``operator.is_`` """ return operator.is_
Example #27
Source File: test_bool.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)
Example #28
Source File: test_itertools.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_accumulate_reducible_none(self): # Issue #25718: total is None it = accumulate([None, None, None], operator.is_) self.assertEqual(next(it), None) for proto in range(pickle.HIGHEST_PROTOCOL + 1): it_copy = pickle.loads(pickle.dumps(it, proto)) self.assertEqual(list(it_copy), [True, False]) self.assertEqual(list(copy.deepcopy(it)), [True, False]) self.assertEqual(list(copy.copy(it)), [True, False])
Example #29
Source File: conftest.py From fletcher with MIT License | 5 votes |
def na_cmp(): """Binary operator for comparing NA values. Should return a function of two arguments that returns True if both arguments are (scalar) NA for your type. By default, uses ``operator.is_`` """ return operator.is_
Example #30
Source File: test_bool.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) with test_support.check_py3k_warnings(): self.assertIs(operator.isCallable(0), False) self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.isSequenceType(0), False) self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.isMappingType(1), False) self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)