@@ -1691,6 +1691,9 @@ let test_convert_all_escaped_free_variables_to_anys _ =
1691
1691
let test_replace_all _ =
1692
1692
let free_variable = Type. Variable (Type.Variable.Unary. create " T" ) in
1693
1693
let annotation = Type. parametric " p" ! [free_variable; Type. integer] in
1694
+ let assert_equal actual expected =
1695
+ assert_equal ~cmp: Type. equal ~printer: Type. show expected actual
1696
+ in
1694
1697
assert_equal
1695
1698
(Type.Variable.GlobalTransforms.Unary. replace_all (fun _ -> Some Type. integer) annotation)
1696
1699
(Type. parametric " p" ! [Type. integer; Type. integer]);
@@ -1727,6 +1730,53 @@ let test_replace_all _ =
1727
1730
CallableParameters
1728
1731
(Defined [Named { name = " p" ; annotation = Type. integer; default = false }]);
1729
1732
]);
1733
+
1734
+ (* Variadic tuples. *)
1735
+ let variadic = Type.Variable.Variadic.Tuple. create " Ts" in
1736
+ let variadic2 = Type.Variable.Variadic.Tuple. create " Ts2" in
1737
+ let assert_replaced ~replace annotation expected =
1738
+ let aliases ?replace_unbound_parameters_with_any :_ = function
1739
+ | "Ts" -> Some (Type. VariableAlias (Type.Variable. TupleVariadic variadic))
1740
+ | "Ts2" -> Some (Type. VariableAlias (Type.Variable. TupleVariadic variadic2))
1741
+ | _ -> None
1742
+ in
1743
+ assert_equal
1744
+ (Type.Variable.GlobalTransforms.TupleVariadic. replace_all
1745
+ replace
1746
+ (Type. create ~aliases (parse_single_expression ~preprocess: true annotation)))
1747
+ (Type. create ~aliases (parse_single_expression ~preprocess: true expected))
1748
+ in
1749
+ let replace_with_concrete given =
1750
+ Option. some_if
1751
+ (Type.Variable.Variadic.Tuple. equal given variadic)
1752
+ (Type.OrderedTypes. Concrete [Type. bool ; Type. bool ])
1753
+ in
1754
+ let replace_with_concatenation _ =
1755
+ Some
1756
+ (Type.OrderedTypes. Concatenation
1757
+ (Type.OrderedTypes.Concatenation. create ~prefix: [Type. bool ] ~suffix: [Type. bool ] variadic))
1758
+ in
1759
+ assert_replaced
1760
+ ~replace: replace_with_concrete
1761
+ " Foo[int, pyre_extensions.Unpack[Ts], str]"
1762
+ " Foo[int, bool, bool, str]" ;
1763
+ assert_replaced
1764
+ ~replace: replace_with_concatenation
1765
+ " Foo[int, pyre_extensions.Unpack[Ts], str]"
1766
+ " Foo[int, bool, pyre_extensions.Unpack[Ts], bool, str]" ;
1767
+ assert_replaced
1768
+ ~replace: replace_with_concrete
1769
+ " Foo[Bar[int, pyre_extensions.Unpack[Ts], str], Bar[int, pyre_extensions.Unpack[Ts2], str]]"
1770
+ " Foo[Bar[int, bool, bool, str], Bar[int, pyre_extensions.Unpack[Ts2], str]]" ;
1771
+ assert_replaced ~replace: replace_with_concrete " typing.Tuple[int, str]" " typing.Tuple[int, str]" ;
1772
+ assert_replaced
1773
+ ~replace: replace_with_concrete
1774
+ " typing.Tuple[int, pyre_extensions.Unpack[Ts], str]"
1775
+ " typing.Tuple[int, bool, bool, str]" ;
1776
+ assert_replaced
1777
+ ~replace: replace_with_concatenation
1778
+ " typing.Tuple[int, pyre_extensions.Unpack[Ts], str]"
1779
+ " typing.Tuple[int, bool, pyre_extensions.Unpack[Ts], bool, str]" ;
1730
1780
()
1731
1781
1732
1782
0 commit comments