Commit ad54b979 authored by Stefan Behnel's avatar Stefan Behnel

Merge branch '0.29.x'

parents 382b5f09 b62774ad
...@@ -198,11 +198,13 @@ def make_dedup_key(outer_type, item_nodes): ...@@ -198,11 +198,13 @@ def make_dedup_key(outer_type, item_nodes):
@return: A tuple that can be used as a dict key for deduplication. @return: A tuple that can be used as a dict key for deduplication.
""" """
item_keys = [ item_keys = [
(py_object_type, None) if node is None (py_object_type, None, type(None)) if node is None
# For sequences and their "mult_factor", see TupleNode. # For sequences and their "mult_factor", see TupleNode.
else make_dedup_key(node.type, [node.mult_factor if node.is_literal else None] + node.args) if node.is_sequence_constructor else make_dedup_key(node.type, [node.mult_factor if node.is_literal else None] + node.args) if node.is_sequence_constructor
else make_dedup_key(node.type, (node.start, node.stop, node.step)) if node.is_slice else make_dedup_key(node.type, (node.start, node.stop, node.step)) if node.is_slice
else (node.type, node.constant_result) if node.has_constant_result() # For constants, look at the Python value type if we don't know the concrete Cython type.
else (node.type, node.constant_result,
type(node.constant_result) if node.type is py_object_type else None) if node.has_constant_result()
else None # something we cannot handle => short-circuit below else None # something we cannot handle => short-circuit below
for node in item_nodes for node in item_nodes
] ]
...@@ -1207,6 +1209,10 @@ class BoolNode(ConstNode): ...@@ -1207,6 +1209,10 @@ class BoolNode(ConstNode):
return str(int(self.value)) return str(int(self.value))
def coerce_to(self, dst_type, env): def coerce_to(self, dst_type, env):
if dst_type == self.type:
return self
if dst_type is py_object_type and self.type is Builtin.bool_type:
return self
if dst_type.is_pyobject and self.type.is_int: if dst_type.is_pyobject and self.type.is_int:
return BoolNode( return BoolNode(
self.pos, value=self.value, self.pos, value=self.value,
......
...@@ -132,3 +132,38 @@ def return_nonconstant_tuple(): ...@@ -132,3 +132,38 @@ def return_nonconstant_tuple():
""" """
a = eval("1") a = eval("1")
return ('a', a, 'd') return ('a', a, 'd')
def constant_types_comparing_equal():
"""
>>> constant_types_comparing_equal()
((False, False), (0, 0), (0.0, 0.0), (0, False), (False, 0.0), (0, 0.0))
"""
bool_tuple= (False, False)
int_tuple = (0, 0)
float_tuple = (0.0, 0.0)
int_bool = (0, False)
bool_float = (False, 0.0)
int_float = (0, 0.0)
assert bool_tuple is (False, False)
assert int_tuple is (0, 0)
assert bool_tuple == int_tuple
assert bool_tuple is not int_tuple
assert float_tuple is (0., 0.)
assert float_tuple == int_tuple
assert float_tuple is not int_tuple
assert int_bool is (0, False)
assert int_bool == bool_tuple
assert int_bool is not bool_tuple
assert int_bool is not int_tuple
assert bool_float is (False, 0.)
assert bool_float == bool_tuple
assert bool_float is not bool_tuple
assert bool_float is not float_tuple
assert int_float is (0, 0.)
assert int_float == int_tuple
assert int_float is not int_tuple
assert int_float is not float_tuple
return bool_tuple, int_tuple, float_tuple, int_bool, bool_float, int_float
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment