@@ -632,17 +632,29 @@ def __iter__(self):
632
632
class FormalMappingLike (BareMappingLike , Mapping ):
633
633
pass
634
634
635
+ a1b2c3 = {"a" : 1 , "b" : 2 , "c" : 3 }
636
+ # convert mode
635
637
assert (
636
638
doc (m .roundtrip_std_map_str_int )
637
639
== "roundtrip_std_map_str_int(arg0: collections.abc.Mapping[str, typing.SupportsInt]) -> dict[str, int]"
638
640
)
639
- a1b2c3 = {"a" : 1 , "b" : 2 , "c" : 3 }
640
641
assert m .roundtrip_std_map_str_int (a1b2c3 ) == a1b2c3
641
642
assert m .roundtrip_std_map_str_int (FormalMappingLike (** a1b2c3 )) == a1b2c3
642
643
assert m .roundtrip_std_map_str_int ({}) == {}
643
644
assert m .roundtrip_std_map_str_int (FormalMappingLike ()) == {}
644
645
with pytest .raises (TypeError ):
645
646
m .roundtrip_std_map_str_int (BareMappingLike (** a1b2c3 ))
647
+ # noconvert mode
648
+ assert (
649
+ doc (m .roundtrip_std_map_str_int_noconvert )
650
+ == "roundtrip_std_map_str_int_noconvert(m: dict[str, int]) -> dict[str, int]"
651
+ )
652
+ assert m .roundtrip_std_map_str_int_noconvert (a1b2c3 ) == a1b2c3
653
+ assert m .roundtrip_std_map_str_int_noconvert ({}) == {}
654
+ with pytest .raises (TypeError ):
655
+ m .roundtrip_std_map_str_int_noconvert (FormalMappingLike (** a1b2c3 ))
656
+ with pytest .raises (TypeError ):
657
+ m .roundtrip_std_map_str_int_noconvert (BareMappingLike (** a1b2c3 ))
646
658
647
659
648
660
def test_set_caster_protocol (doc ):
@@ -667,6 +679,7 @@ def __iter__(self):
667
679
class FormalSetLike (BareSetLike , Set ):
668
680
pass
669
681
682
+ # convert mode
670
683
assert (
671
684
doc (m .roundtrip_std_set_int )
672
685
== "roundtrip_std_set_int(arg0: collections.abc.Set[typing.SupportsInt]) -> set[int]"
@@ -677,3 +690,14 @@ class FormalSetLike(BareSetLike, Set):
677
690
assert m .roundtrip_std_set_int (FormalSetLike ()) == set ()
678
691
with pytest .raises (TypeError ):
679
692
m .roundtrip_std_set_int (BareSetLike (1 , 2 , 3 ))
693
+ # noconvert mode
694
+ assert (
695
+ doc (m .roundtrip_std_set_int_noconvert )
696
+ == "roundtrip_std_set_int_noconvert(s: set[int]) -> set[int]"
697
+ )
698
+ assert m .roundtrip_std_set_int_noconvert ({1 , 2 , 3 }) == {1 , 2 , 3 }
699
+ assert m .roundtrip_std_set_int_noconvert (set ()) == set ()
700
+ with pytest .raises (TypeError ):
701
+ m .roundtrip_std_set_int_noconvert (FormalSetLike (1 , 2 , 3 ))
702
+ with pytest .raises (TypeError ):
703
+ m .roundtrip_std_set_int_noconvert (BareSetLike (1 , 2 , 3 ))
0 commit comments