MCPcopy Index your code
hub / github.com/python/mypy / transform_basic_comparison

Function transform_basic_comparison

mypyc/irbuild/expression.py:1048–1097  ·  view source on GitHub ↗

Transform single comparison. 'op' must be one of these: '==', '!=', '<', '<=', '>', '>=' 'in', 'not in' 'is', 'is not'

(
    builder: IRBuilder, op: str, left: Value, right: Value, line: int
)

Source from the content-addressed store, hash-verified

1046
1047
1048def transform_basic_comparison(
1049 builder: IRBuilder, op: str, left: Value, right: Value, line: int
1050) -> Value:
1051 """Transform single comparison.
1052
1053 'op' must be one of these:
1054
1055 '==', '!=', '<', '<=', '>', '>='
1056 'in', 'not in'
1057 'is', 'is not'
1058 """
1059 if is_fixed_width_rtype(left.type) and op in ComparisonOp.signed_ops:
1060 if right.type == left.type:
1061 if left.type.is_signed:
1062 op_id = ComparisonOp.signed_ops[op]
1063 else:
1064 op_id = ComparisonOp.unsigned_ops[op]
1065 return builder.builder.comparison_op(left, right, op_id, line)
1066 elif isinstance(right, Integer):
1067 if left.type.is_signed:
1068 op_id = ComparisonOp.signed_ops[op]
1069 else:
1070 op_id = ComparisonOp.unsigned_ops[op]
1071 return builder.builder.comparison_op(
1072 left, builder.coerce(right, left.type, line), op_id, line
1073 )
1074 elif (
1075 is_fixed_width_rtype(right.type)
1076 and op in ComparisonOp.signed_ops
1077 and isinstance(left, Integer)
1078 ):
1079 if right.type.is_signed:
1080 op_id = ComparisonOp.signed_ops[op]
1081 else:
1082 op_id = ComparisonOp.unsigned_ops[op]
1083 return builder.builder.comparison_op(
1084 builder.coerce(left, right.type, line), right, op_id, line
1085 )
1086
1087 negate = False
1088 if op == "is not":
1089 op, negate = "is", True
1090 elif op == "not in":
1091 op, negate = "in", True
1092
1093 target = builder.binary_op(left, right, op, line)
1094
1095 if negate:
1096 target = builder.unary_op(target, "not", line)
1097 return target
1098
1099
1100def translate_printf_style_formatting(

Callers 2

goFunction · 0.85
try_specialize_in_exprFunction · 0.85

Calls 6

is_fixed_width_rtypeFunction · 0.90
isinstanceFunction · 0.85
comparison_opMethod · 0.80
coerceMethod · 0.45
binary_opMethod · 0.45
unary_opMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…