◐ Shell
reader mode source ↗
Skip to content
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
46 changes: 30 additions & 16 deletions Lib/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,18 +527,16 @@ def test(f, format_spec, result):
self.assertRaises(TypeError, 3.0.__format__, None)
self.assertRaises(TypeError, 3.0.__format__, 0)

# other format specifiers shouldn't work on floats,
# in particular int specifiers
for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
[chr(x) for x in range(ord('A'), ord('Z')+1)]):
if not format_spec in 'eEfFgGn%':
self.assertRaises(ValueError, format, 0.0, format_spec)
self.assertRaises(ValueError, format, 1.0, format_spec)
self.assertRaises(ValueError, format, -1.0, format_spec)
self.assertRaises(ValueError, format, 1e100, format_spec)
self.assertRaises(ValueError, format, -1e100, format_spec)
self.assertRaises(ValueError, format, 1e-100, format_spec)
self.assertRaises(ValueError, format, -1e-100, format_spec)

# Alternate float formatting
test(1.0, '.0e', '1e+00')
Expand Down Expand Up @@ -604,6 +602,14 @@ def test_slot_wrapper_types(self):
self.assertIsInstance(object.__lt__, types.WrapperDescriptorType)
self.assertIsInstance(int.__lt__, types.WrapperDescriptorType)

def test_method_wrapper_types(self):
self.assertIsInstance(object().__init__, types.MethodWrapperType)
self.assertIsInstance(object().__str__, types.MethodWrapperType)
Expand All @@ -629,6 +635,14 @@ def test_notimplemented_type(self):
def test_none_type(self):
self.assertIsInstance(None, types.NoneType)


class UnionTests(unittest.TestCase):

Expand Down Expand Up @@ -878,7 +892,7 @@ def test_union_parameter_substitution_errors(self):
T = typing.TypeVar("T")
x = int | T
with self.assertRaises(TypeError):
x[42]

def test_or_type_operator_with_forward(self):
T = typing.TypeVar('T')
Expand Down @@ -958,9 +972,9 @@ def __eq__(self, other):
with self.assertRaises(ZeroDivisionError):
list[int] | list[bt]

union_ga = (int | list[str], int | collections.abc.Callable[..., str],
int | d)
# Raise error when isinstance(type, type | genericalias)
for type_ in union_ga:
with self.subTest(f"check isinstance/issubclass is invalid for {type_}"):
with self.assertRaises(TypeError):
Expand Down
Toggle all file notes Toggle all file annotations