Exemple #1
0
 def test_false_only_tuple(self) -> None:
     with strict_optional_set(False):
         fo = false_only(self.tuple(self.fx.a))
         assert_equal(fo, NoneType())
     with strict_optional_set(True):
         fo = false_only(self.tuple(self.fx.a))
         assert_equal(fo, UninhabitedType())
Exemple #2
0
 def test_mixed_truth_restricted_type(self) -> None:
     # join_types against differently restricted truthiness types drops restrictions.
     true_any = true_only(AnyType(TypeOfAny.special_form))
     false_o = false_only(self.fx.o)
     j = join_types(true_any, false_o)
     assert_true(j.can_be_true)
     assert_true(j.can_be_false)
Exemple #3
0
 def test_mixed_truth_restricted_type_simple(self) -> None:
     # join_simple against differently restricted truthiness types drops restrictions.
     true_a = true_only(self.fx.a)
     false_o = false_only(self.fx.o)
     j = join_simple(self.fx.o, true_a, false_o)
     assert_true(j.can_be_true)
     assert_true(j.can_be_false)
Exemple #4
0
 def test_false_only_of_instance(self) -> None:
     fo = false_only(self.fx.a)
     assert_equal(str(fo), "A")
     assert_false(fo.can_be_true)
     assert_true(fo.can_be_false)
     assert_type(Instance, fo)
     # The original class still can be true
     assert_true(self.fx.a.can_be_true)
Exemple #5
0
 def test_false_only_of_union(self) -> None:
     with strict_optional_set(True):
         tup_type = self.tuple()
         # Union of something that is unknown, something that is always true, something
         # that is always false
         union_type = UnionType([self.fx.a, self.tuple(AnyType(TypeOfAny.special_form)),
                                 tup_type])
         assert_equal(len(union_type.items), 3)
         fo = false_only(union_type)
         assert isinstance(fo, UnionType)
         assert_equal(len(fo.items), 2)
         assert not fo.items[0].can_be_true
         assert fo.items[0].can_be_false
         assert fo.items[1] is tup_type
Exemple #6
0
 def test_false_only_of_false_type_is_idempotent(self) -> None:
     always_false = NoneType()
     fo = false_only(always_false)
     assert_true(always_false is fo)
Exemple #7
0
 def test_false_only_of_true_type_is_uninhabited(self) -> None:
     with strict_optional_set(True):
         fo = false_only(self.tuple(AnyType(TypeOfAny.special_form)))
         assert_type(UninhabitedType, fo)