Python ast.Gt() Examples
The following are 27
code examples of ast.Gt().
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
ast
, or try the search function
.
Example #1
Source File: helper.py From YAPyPy with MIT License | 6 votes |
def comp_op_rewrite(op: t.Union[Tokenizer, t.List[Tokenizer]]): """ ('<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not') """ if isinstance(op, list): op = tuple(map(lambda it: it.value, op)) else: op = op.value return { '<': ast.Lt, '>': ast.Gt, '==': ast.Eq, '>=': ast.GtE, '<=': ast.LtE, '<>': lambda: raise_exp(NotImplemented), '!=': ast.NotEq, 'in': ast.In, ('is', ): ast.Is, ('is', 'not'): ast.IsNot, ('not', 'in'): ast.NotIn, }[op]()
Example #2
Source File: rewrite.py From ward with MIT License | 6 votes |
def visit_Assert(self, node): if is_binary_comparison(node): if is_comparison_type(node, ast.Eq): return make_call_node(node, assert_equal.__name__) elif is_comparison_type(node, ast.NotEq): return make_call_node(node, assert_not_equal.__name__) elif is_comparison_type(node, ast.In): return make_call_node(node, assert_in.__name__) elif is_comparison_type(node, ast.NotIn): return make_call_node(node, assert_not_in.__name__) elif is_comparison_type(node, ast.Is): return make_call_node(node, assert_is.__name__) elif is_comparison_type(node, ast.IsNot): return make_call_node(node, assert_is_not.__name__) elif is_comparison_type(node, ast.Lt): return make_call_node(node, assert_less_than.__name__) elif is_comparison_type(node, ast.LtE): return make_call_node(node, assert_less_than_equal_to.__name__) elif is_comparison_type(node, ast.Gt): return make_call_node(node, assert_greater_than.__name__) elif is_comparison_type(node, ast.GtE): return make_call_node(node, assert_greater_than_equal_to.__name__) return node
Example #3
Source File: python2ir.py From ppci with BSD 2-Clause "Simplified" License | 6 votes |
def gen_compare(self, condition, yes_block, no_block): # print(dir(c), c.ops, c.comparators) # TODO: chained operators! ( 'a < b < c < d' ) assert len(condition.ops) == len(condition.comparators) assert len(condition.ops) == 1 op_map = { ast.Gt: ">", ast.GtE: ">=", ast.Lt: "<", ast.LtE: "<=", ast.Eq: "==", ast.NotEq: "!=", } a = self.gen_expr(condition.left) op = op_map[type(condition.ops[0])] b = self.gen_expr(condition.comparators[0]) if a.ty is not b.ty: self.error(condition, "Type mismatch, types must be the same.") self.emit(ir.CJump(a, op, b, yes_block, no_block))
Example #4
Source File: pycode_similar.py From pycode_similar with MIT License | 6 votes |
def visit_Compare(self, node): def _simple_nomalize(*ops_type_names): if node.ops and len(node.ops) == 1 and type(node.ops[0]).__name__ in ops_type_names: if node.left and node.comparators and len(node.comparators) == 1: left, right = node.left, node.comparators[0] if type(left).__name__ > type(right).__name__: left, right = right, left node.left = left node.comparators = [right] return True return False if _simple_nomalize('Eq'): pass if _simple_nomalize('Gt', 'Lt'): node.ops = [{ast.Lt: ast.Gt, ast.Gt: ast.Lt}[type(node.ops[0])]()] if _simple_nomalize('GtE', 'LtE'): node.ops = [{ast.LtE: ast.GtE, ast.GtE: ast.LtE}[type(node.ops[0])]()] self.generic_visit(node) return node
Example #5
Source File: parser.py From vecpy with MIT License | 6 votes |
def cmpop(self, op): if isinstance(op, ast.Eq): return Operator.eq elif isinstance(op, ast.NotEq): return Operator.ne elif isinstance(op, ast.Lt): return Operator.lt elif isinstance(op, ast.LtE): return Operator.le elif isinstance(op, ast.Gt): return Operator.gt elif isinstance(op, ast.GtE): return Operator.ge else: raise Exception('Unexpected CmpOp (%s)'%(op.__class__)) #Parses a function call (AST Call)
Example #6
Source File: compares.py From wemake-python-styleguide with MIT License | 5 votes |
def _mutate( self, comparison_node: ast.Compare, operator: ast.cmpop, name: str, is_left: bool, ) -> None: key_name = None if isinstance(operator, (ast.Lt, ast.LtE)): key_name = 'lower_bound' if is_left else 'upper_bound' elif isinstance(operator, (ast.Gt, ast.GtE)): key_name = 'upper_bound' if is_left else 'lower_bound' if key_name: getattr(self._uses[name], key_name).add(comparison_node)
Example #7
Source File: ast_nodes_validators.py From fiasko_bro with MIT License | 5 votes |
def _is_compared_with_zero(node): return ( isinstance(node.ops[0], (ast.Gt, ast.Eq)) and isinstance(node.comparators[0], ast.Num) and node.comparators[0].n == 0 )
Example #8
Source File: compares.py From wemake-python-styleguide with MIT License | 5 votes |
def _check_reversed_complex_compare(self, node: ast.Compare) -> None: if len(node.ops) != 2: return is_less = all( isinstance(op, (ast.Gt, ast.GtE)) for op in node.ops ) if not is_less: return self.add_violation(ReversedComplexCompareViolation(node))
Example #9
Source File: compiler.py From Transcrypt with Apache License 2.0 | 5 votes |
def visit_Compare (self, node): if len (node.comparators) > 1: self.emit ('(') left = node.left for index, (op, right) in enumerate (zip (node.ops, node.comparators)): if index: self.emit (' && ') if type (op) in (ast.In, ast.NotIn) or (self.allowOperatorOverloading and type (op) in ( ast.Eq, ast.NotEq, ast.Lt, ast.LtE, ast.Gt, ast.GtE )): self.emit ('{} ('.format (self.filterId ( # Non-overloaded '__in__' if type (op) == ast.In else '!__in__' if type (op) == ast.NotIn else # Overloaded '__eq__' if type (op) == ast.Eq else '__ne__' if type (op) == ast.NotEq else '__lt__' if type (op) == ast.Lt else '__le__' if type (op) == ast.LtE else '__gt__' if type (op) == ast.Gt else '__ge__' if type (op) == ast.GtE else 'Never here' ))) self.visitSubExpr (node, left) self.emit (', ') self.visitSubExpr (node, right) self.emit (')') else: self.visitSubExpr (node, left) self.emit (' {0} '.format (self.operators [type (op)][0])) self.visitSubExpr (node, right) left = right if len (node.comparators) > 1: self.emit(')')
Example #10
Source File: definitions.py From vkbottle with MIT License | 5 votes |
def gt_operator(d: ast.Gt): return "!="
Example #11
Source File: definitions.py From vkbottle with MIT License | 5 votes |
def gt_operator(d: ast.Gt): return ">"
Example #12
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #13
Source File: hgawk_grammar.py From histogrammar-python with Apache License 2.0 | 5 votes |
def p_comp_op_2(p): '''comp_op : GREATER''' # 1 p[0] = ast.Gt(rule=inspect.currentframe().f_code.co_name)
Example #14
Source File: test_ast.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #15
Source File: _recompute.py From icontract with MIT License | 5 votes |
def visit_Compare(self, node: ast.Compare) -> Any: """Recursively visit the comparators and apply the operations on them.""" # pylint: disable=too-many-branches left = self.visit(node=node.left) comparators = [self.visit(node=comparator) for comparator in node.comparators] result = None # type: Optional[Any] for comparator, op in zip(comparators, node.ops): if isinstance(op, ast.Eq): comparison = left == comparator elif isinstance(op, ast.NotEq): comparison = left != comparator elif isinstance(op, ast.Lt): comparison = left < comparator elif isinstance(op, ast.LtE): comparison = left <= comparator elif isinstance(op, ast.Gt): comparison = left > comparator elif isinstance(op, ast.GtE): comparison = left >= comparator elif isinstance(op, ast.Is): comparison = left is comparator elif isinstance(op, ast.IsNot): comparison = left is not comparator elif isinstance(op, ast.In): comparison = left in comparator elif isinstance(op, ast.NotIn): comparison = left not in comparator else: raise NotImplementedError("Unhandled op of {}: {}".format(node, op)) if result is None: result = comparison else: result = result and comparison left = comparator self.recomputed_values[node] = result return result
Example #16
Source File: test_ast.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #17
Source File: test_ast.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #18
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #19
Source File: BehavioralRTLIRGenL2Pass.py From pymtl3 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__( s, component ): super().__init__( component ) s.loop_var_env = set() s.tmp_var_env = set() # opmap maps an ast operator to its RTLIR counterpart. s.opmap = { # Bool operators # Note: we do not support boolean operators because Python does # not allow overloading And and Or operators. Using them in # expressions might lead to inconsistent semantics. # ast.And : bir.And(), ast.Or : bir.Or(), # Unary operators # Note: ast.Not is disallowed because it is a boolean operator # ast.Not : bir.Not(), ast.Invert : bir.Invert(), ast.UAdd : bir.UAdd(), ast.USub : bir.USub(), # Binary operators ast.Add : bir.Add(), ast.Sub : bir.Sub(), ast.Mult : bir.Mult(), ast.Div : bir.Div(), ast.Mod : bir.Mod(), ast.Pow : bir.Pow(), ast.LShift : bir.ShiftLeft(), ast.RShift : bir.ShiftRightLogic(), ast.BitOr : bir.BitOr(), ast.BitAnd : bir.BitAnd(), ast.BitXor : bir.BitXor(), # Compare bir.bir.operators ast.Eq : bir.Eq(), ast.NotEq : bir.NotEq(), ast.Lt : bir.Lt(), ast.LtE : bir.LtE(), ast.Gt : bir.Gt(), ast.GtE : bir.GtE() } # Override
Example #20
Source File: test_ast.py From oss-ftp with MIT License | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #21
Source File: test_ast.py From BinderFilter with MIT License | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #22
Source File: builder.py From staticfg with Apache License 2.0 | 5 votes |
def invert(node): """ Invert the operation in an ast node object (get its negation). Args: node: An ast node object. Returns: An ast node object containing the inverse (negation) of the input node. """ inverse = {ast.Eq: ast.NotEq, ast.NotEq: ast.Eq, ast.Lt: ast.GtE, ast.LtE: ast.Gt, ast.Gt: ast.LtE, ast.GtE: ast.Lt, ast.Is: ast.IsNot, ast.IsNot: ast.Is, ast.In: ast.NotIn, ast.NotIn: ast.In} if type(node) == ast.Compare: op = type(node.ops[0]) inverse_node = ast.Compare(left=node.left, ops=[inverse[op]()], comparators=node.comparators) elif isinstance(node, ast.BinOp) and type(node.op) in inverse: op = type(node.op) inverse_node = ast.BinOp(node.left, inverse[op](), node.right) elif type(node) == ast.NameConstant and node.value in [True, False]: inverse_node = ast.NameConstant(value=not node.value) else: inverse_node = ast.UnaryOp(op=ast.Not(), operand=node) return inverse_node
Example #23
Source File: pyast64.py From pyast64 with MIT License | 5 votes |
def visit_For(self, node): # Turn for+range loop into a while loop: # i = start # while i < stop: # body # i = i + step assert isinstance(node.iter, ast.Call) and \ node.iter.func.id == 'range', \ 'for can only be used with range()' range_args = node.iter.args if len(range_args) == 1: start = ast.Num(n=0) stop = range_args[0] step = ast.Num(n=1) elif len(range_args) == 2: start, stop = range_args step = ast.Num(n=1) else: start, stop, step = range_args if (isinstance(step, ast.UnaryOp) and isinstance(step.op, ast.USub) and isinstance(step.operand, ast.Num)): # Handle negative step step = ast.Num(n=-step.operand.n) assert isinstance(step, ast.Num) and step.n != 0, \ 'range() step must be a nonzero integer constant' self.visit(ast.Assign(targets=[node.target], value=start)) test = ast.Compare( left=node.target, ops=[ast.Lt() if step.n > 0 else ast.Gt()], comparators=[stop], ) incr = ast.Assign( targets=[node.target], value=ast.BinOp(left=node.target, op=ast.Add(), right=step), ) self.visit(ast.While(test=test, body=node.body + [incr]))
Example #24
Source File: test_ast.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #25
Source File: test_ast.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) self.assertTrue(issubclass(ast.stmt, ast.AST)) self.assertTrue(issubclass(ast.expr, ast.AST)) self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST))
Example #26
Source File: _ast_to_ir2.py From tmppy with Apache License 2.0 | 5 votes |
def compare_ast_to_ir2(ast_node: ast.Compare, compilation_context: CompilationContext, in_match_pattern: bool, check_var_reference: Callable[[ast.Name], None], match_lambda_argument_names: Set[str], current_stmt_line: int): if len(ast_node.ops) != 1 or len(ast_node.comparators) != 1: raise CompilationError(compilation_context, ast_node, 'Comparison not supported.') # pragma: no cover if in_match_pattern: raise CompilationError(compilation_context, ast_node, 'Comparisons are not allowed in match patterns') lhs = ast_node.left op = ast_node.ops[0] rhs = ast_node.comparators[0] if isinstance(op, ast.Eq): return eq_ast_to_ir2(lhs, rhs, compilation_context, in_match_pattern, check_var_reference, current_stmt_line) elif isinstance(op, ast.NotEq): return not_eq_ast_to_ir2(lhs, rhs, compilation_context, in_match_pattern, check_var_reference, current_stmt_line) elif isinstance(op, ast.In): return in_ast_to_ir2(lhs, rhs, compilation_context, in_match_pattern, check_var_reference, current_stmt_line) elif isinstance(op, ast.Lt): return int_comparison_ast_to_ir2(lhs, rhs, '<', compilation_context, in_match_pattern, check_var_reference, current_stmt_line) elif isinstance(op, ast.LtE): return int_comparison_ast_to_ir2(lhs, rhs, '<=', compilation_context, in_match_pattern, check_var_reference, current_stmt_line) elif isinstance(op, ast.Gt): return int_comparison_ast_to_ir2(lhs, rhs, '>', compilation_context, in_match_pattern, check_var_reference, current_stmt_line) elif isinstance(op, ast.GtE): return int_comparison_ast_to_ir2(lhs, rhs, '>=', compilation_context, in_match_pattern, check_var_reference, current_stmt_line) else: raise CompilationError(compilation_context, ast_node, 'Comparison not supported.') # pragma: no cover
Example #27
Source File: pyupgrade.py From pyupgrade with MIT License | 4 votes |
def visit_If(self, node: ast.If) -> None: if ( # if six.PY2: self._is_six(node.test, ('PY2',)) or # if not six.PY3: ( isinstance(node.test, ast.UnaryOp) and isinstance(node.test.op, ast.Not) and self._is_six(node.test.operand, ('PY3',)) ) or # sys.version_info == 2 or < (3,) ( isinstance(node.test, ast.Compare) and self._is_version_info(node.test.left) and len(node.test.ops) == 1 and ( self._eq(node.test, 2) or self._compare_to_3(node.test, ast.Lt) ) ) ): if node.orelse and not isinstance(node.orelse[0], ast.If): self.if_py2_blocks_else.add(_ast_to_offset(node)) elif ( # if six.PY3: self._is_six(node.test, 'PY3') or # if not six.PY2: ( isinstance(node.test, ast.UnaryOp) and isinstance(node.test.op, ast.Not) and self._is_six(node.test.operand, ('PY2',)) ) or # sys.version_info == 3 or >= (3,) or > (3,) ( isinstance(node.test, ast.Compare) and self._is_version_info(node.test.left) and len(node.test.ops) == 1 and ( self._eq(node.test, 3) or self._compare_to_3(node.test, (ast.Gt, ast.GtE)) ) ) ): if node.orelse and not isinstance(node.orelse[0], ast.If): self.if_py3_blocks_else.add(_ast_to_offset(node)) elif not node.orelse: self.if_py3_blocks.add(_ast_to_offset(node)) self.generic_visit(node)