Пример #1
0
def test_optional_types():
    DT = Dict()
    DT2 = Dict(Signed, Float)
    assert DT != Signed
    py.test.raises(TypeError, "DT == DT2")
    py.test.raises(TypeError, "DT2 == DT")
    py.test.raises(TypeError, hash, DT)
    setDictTypes(DT, Signed, Float)
    assert DT == DT2
    assert DT2 == DT
    assert hash(DT) == hash(DT2)
Пример #2
0
    def _setup_repr(self):
        if "key_repr" not in self.__dict__:
            key_repr = self._key_repr_computer()
            self.external_key_repr, self.key_repr = self.pickkeyrepr(key_repr)
        if "value_repr" not in self.__dict__:
            self.external_value_repr, self.value_repr = self.pickrepr(self._value_repr_computer())

        if not ootype.hasDictTypes(self.DICT):
            ootype.setDictTypes(self.DICT, self.key_repr.lowleveltype, self.value_repr.lowleveltype)

        if self.custom_eq_hash:
            self.r_rdict_eqfn, self.r_rdict_hashfn = self._custom_eq_hash_repr()
Пример #3
0
    def _setup_repr(self):
        if 'key_repr' not in self.__dict__:
            key_repr = self._key_repr_computer()
            self.external_key_repr, self.key_repr = self.pickkeyrepr(key_repr)
        if 'value_repr' not in self.__dict__:
            self.external_value_repr, self.value_repr = self.pickrepr(
                self._value_repr_computer())

        if not ootype.hasDictTypes(self.DICT):
            ootype.setDictTypes(self.DICT, self.key_repr.lowleveltype,
                                self.value_repr.lowleveltype)

        if self.custom_eq_hash:
            self.r_rdict_eqfn, self.r_rdict_hashfn = self._custom_eq_hash_repr(
            )
Пример #4
0
def test_recursive_str_hash():
    DT = Dict()
    setDictTypes(DT, Signed, DT)
    assert isinstance(str(DT), str)
    assert isinstance(hash(DT), int)