我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用symbol.or_test()。
def get_op(cls, op): ops = { symbol.test: cls.test, symbol.and_test: cls.and_test, symbol.atom: cls.atom, symbol.comparison: cls.comparison, 'not in': lambda x, y: x not in y, 'in': lambda x, y: x in y, '==': operator.eq, '!=': operator.ne, '<': operator.lt, '>': operator.gt, '<=': operator.le, '>=': operator.ge, } if hasattr(symbol, 'or_test'): ops[symbol.or_test] = cls.test return ops[op]
def get_op(cls, op): ops = { symbol.test: cls.test, symbol.and_test: cls.and_test, symbol.atom: cls.atom, symbol.comparison: cls.comparison, 'not in': lambda x, y: x not in y, 'in': lambda x, y: x in y, '==': operator.eq, '!=': operator.ne, } if hasattr(symbol, 'or_test'): ops[symbol.or_test] = cls.test return ops[op]
def test(self, nodelist): # or_test ['if' or_test 'else' test] | lambdef if len(nodelist) == 1 and nodelist[0][0] == symbol.lambdef: return self.lambdef(nodelist[0]) then = self.com_node(nodelist[0]) if len(nodelist) > 1: assert len(nodelist) == 5 assert nodelist[1][1] == 'if' assert nodelist[3][1] == 'else' test = self.com_node(nodelist[2]) else_ = self.com_node(nodelist[4]) return IfExp(test, then, else_, lineno=nodelist[1][2]) return then
def or_test(self, nodelist): # and_test ('or' and_test)* | lambdef if len(nodelist) == 1 and nodelist[0][0] == symbol.lambdef: return self.lambdef(nodelist[0]) return self.com_binary(Or, nodelist)