Skip to content

Commit f583f9a

Browse files
authored
Merge pull request #4683 from tdub0/test_types_modify
Update test/test_types from CPython 3.11.2
2 parents 415cdb1 + b458797 commit f583f9a

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

Lib/test/test_types.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -527,18 +527,16 @@ def test(f, format_spec, result):
527527
self.assertRaises(TypeError, 3.0.__format__, None)
528528
self.assertRaises(TypeError, 3.0.__format__, 0)
529529

530-
# other format specifiers shouldn't work on floats,
531-
# in particular int specifiers
532-
for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
533-
[chr(x) for x in range(ord('A'), ord('Z')+1)]):
534-
if not format_spec in 'eEfFgGn%':
535-
self.assertRaises(ValueError, format, 0.0, format_spec)
536-
self.assertRaises(ValueError, format, 1.0, format_spec)
537-
self.assertRaises(ValueError, format, -1.0, format_spec)
538-
self.assertRaises(ValueError, format, 1e100, format_spec)
539-
self.assertRaises(ValueError, format, -1e100, format_spec)
540-
self.assertRaises(ValueError, format, 1e-100, format_spec)
541-
self.assertRaises(ValueError, format, -1e-100, format_spec)
530+
# confirm format options expected to fail on floats, such as integer
531+
# presentation types
532+
for format_spec in 'sbcdoxX':
533+
self.assertRaises(ValueError, format, 0.0, format_spec)
534+
self.assertRaises(ValueError, format, 1.0, format_spec)
535+
self.assertRaises(ValueError, format, -1.0, format_spec)
536+
self.assertRaises(ValueError, format, 1e100, format_spec)
537+
self.assertRaises(ValueError, format, -1e100, format_spec)
538+
self.assertRaises(ValueError, format, 1e-100, format_spec)
539+
self.assertRaises(ValueError, format, -1e-100, format_spec)
542540

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

605+
# TODO: RUSTPYTHON No signature found in builtin method __get__ of 'method_descriptor' objects.
606+
@unittest.expectedFailure
607+
def test_dunder_get_signature(self):
608+
sig = inspect.signature(object.__init__.__get__)
609+
self.assertEqual(list(sig.parameters), ["instance", "owner"])
610+
# gh-93021: Second parameter is optional
611+
self.assertIs(sig.parameters["owner"].default, None)
612+
607613
def test_method_wrapper_types(self):
608614
self.assertIsInstance(object().__init__, types.MethodWrapperType)
609615
self.assertIsInstance(object().__str__, types.MethodWrapperType)
@@ -629,6 +635,14 @@ def test_notimplemented_type(self):
629635
def test_none_type(self):
630636
self.assertIsInstance(None, types.NoneType)
631637

638+
def test_traceback_and_frame_types(self):
639+
try:
640+
raise OSError
641+
except OSError as e:
642+
exc = e
643+
self.assertIsInstance(exc.__traceback__, types.TracebackType)
644+
self.assertIsInstance(exc.__traceback__.tb_frame, types.FrameType)
645+
632646

633647
class UnionTests(unittest.TestCase):
634648

@@ -878,7 +892,7 @@ def test_union_parameter_substitution_errors(self):
878892
T = typing.TypeVar("T")
879893
x = int | T
880894
with self.assertRaises(TypeError):
881-
x[42]
895+
x[int, str]
882896

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

961-
union_ga = (int | list[str], int | collections.abc.Callable[..., str],
962-
int | d)
963-
# Raise error when isinstance(type, type | genericalias)
975+
union_ga = (list[str] | int, collections.abc.Callable[..., str] | int,
976+
d | int)
977+
# Raise error when isinstance(type, genericalias | type)
964978
for type_ in union_ga:
965979
with self.subTest(f"check isinstance/issubclass is invalid for {type_}"):
966980
with self.assertRaises(TypeError):

0 commit comments

Comments
 (0)