本文整理匯總了Python中operator.is_方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.is_方法的具體用法?Python operator.is_怎麽用?Python operator.is_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類operator
的用法示例。
在下文中一共展示了operator.is_方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _validate_query_state
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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, )
)
示例2: test_operator
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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)
示例3: add_globals
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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
示例4: get_all_payloads_with_value
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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
示例5: is_
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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."
)
示例6: test_operator
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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)
示例7: __init__
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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_,
}
示例8: _validate_query_state
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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,)
)
示例9: na_cmp
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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_
示例10: test_is
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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))
示例11: test_operator
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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)
示例12: standard_env
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
def standard_env():
env = Env()
env.update(vars(math))
env.update({
'+':op.add,
'-':op.sub,
'*':op.mul,
'/':op.div,
'>':op.gt,
'<':op.lt,
'>=':op.ge,
'<=':op.le,
'=':op.eq,
'abs': abs,
'append': op.add,
'apply': apply,
'begin': lambda *x: x[-1],
'car': lambda x: x[0],
'cdr': lambda x: x[1:],
'cons': lambda x,y: [x] + y,
'eq?': op.is_,
'equal?': op.eq,
'length': len,
'list': lambda *x: list(x),
'list?': lambda x: isinstance(x,list),
'map': map,
'max': max,
'filter': filter,
'foldr': foldr,
'foldl': foldl,
'min': min,
'not': op.not_,
'null?': lambda x: x == [],
'number?': lambda x: isinstance(x, Number),
'procedure?': callable,
'round': round,
'symbol?': lambda x: isinstance(x, Symbol),
})
return env
示例13: test_accumulate_reducible_none
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import is_ [as 別名]
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])