@@ -527,18 +527,16 @@ def test(f, format_spec, result):
527
527
self .assertRaises (TypeError , 3.0 .__format__ , None )
528
528
self .assertRaises (TypeError , 3.0 .__format__ , 0 )
529
529
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 )
542
540
543
541
# Alternate float formatting
544
542
test (1.0 , '.0e' , '1e+00' )
@@ -604,6 +602,14 @@ def test_slot_wrapper_types(self):
604
602
self .assertIsInstance (object .__lt__ , types .WrapperDescriptorType )
605
603
self .assertIsInstance (int .__lt__ , types .WrapperDescriptorType )
606
604
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
+
607
613
def test_method_wrapper_types (self ):
608
614
self .assertIsInstance (object ().__init__ , types .MethodWrapperType )
609
615
self .assertIsInstance (object ().__str__ , types .MethodWrapperType )
@@ -629,6 +635,14 @@ def test_notimplemented_type(self):
629
635
def test_none_type (self ):
630
636
self .assertIsInstance (None , types .NoneType )
631
637
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
+
632
646
633
647
class UnionTests (unittest .TestCase ):
634
648
@@ -878,7 +892,7 @@ def test_union_parameter_substitution_errors(self):
878
892
T = typing .TypeVar ("T" )
879
893
x = int | T
880
894
with self .assertRaises (TypeError ):
881
- x [42 ]
895
+ x [int , str ]
882
896
883
897
def test_or_type_operator_with_forward (self ):
884
898
T = typing .TypeVar ('T' )
@@ -958,9 +972,9 @@ def __eq__(self, other):
958
972
with self .assertRaises (ZeroDivisionError ):
959
973
list [int ] | list [bt ]
960
974
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 )
964
978
for type_ in union_ga :
965
979
with self .subTest (f"check isinstance/issubclass is invalid for { type_ } " ):
966
980
with self .assertRaises (TypeError ):
0 commit comments