예제 #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())
예제 #2
0
파일: testtypes.py 프로젝트: python/mypy
 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)
예제 #3
0
파일: testtypes.py 프로젝트: python/mypy
 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)
예제 #4
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)
예제 #5
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)
예제 #6
0
파일: testtypes.py 프로젝트: python/mypy
 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)
예제 #7
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)
예제 #8
0
 def test_false_only_of_union(self):
     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()), tup_type])
     assert_equal(len(union_type.items), 3)
     fo = false_only(union_type)
     assert_equal(len(fo.items), 2)
     assert_false(fo.items[0].can_be_true)
     assert_true(fo.items[0].can_be_false)
     assert_true(fo.items[1] is tup_type)
예제 #9
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_false(fo.items[0].can_be_true)
         assert_true(fo.items[0].can_be_false)
         assert_true(fo.items[1] is tup_type)
예제 #10
0
파일: testtypes.py 프로젝트: python/mypy
 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)
예제 #11
0
파일: testtypes.py 프로젝트: python/mypy
 def test_false_only_of_true_type_is_uninhabited(self) -> None:
     fo = false_only(self.tuple(AnyType(TypeOfAny.special_form)))
     assert_type(UninhabitedType, fo)
예제 #12
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)
예제 #13
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)
예제 #14
0
파일: testtypes.py 프로젝트: zanellia/mypy
 def test_false_only_of_true_type_is_uninhabited(self) -> None:
     fo = false_only(self.tuple(AnyType(TypeOfAny.special_form)))
     assert_type(UninhabitedType, fo)
예제 #15
0
 def test_false_only_of_true_type_is_uninhabited(self):
     fo = false_only(self.tuple(AnyType()))
     assert_type(UninhabitedType, fo)