@@ -357,6 +357,32 @@ def test_vararg_after_star(self):
357
357
"""
358
358
self .expect_failure (block , err , lineno = 6 )
359
359
360
+ def test_double_star_after_var_keyword (self ):
361
+ err = "Function 'my_test_func' has an invalid parameter declaration (**kwargs?): '**kwds: dict'"
362
+ block = """
363
+ /*[clinic input]
364
+ my_test_func
365
+
366
+ pos_arg: object
367
+ **kwds: dict
368
+ **
369
+ [clinic start generated code]*/
370
+ """
371
+ self .expect_failure (block , err , lineno = 5 )
372
+
373
+ def test_var_keyword_after_star (self ):
374
+ err = "Function 'my_test_func' has an invalid parameter declaration: '**'"
375
+ block = """
376
+ /*[clinic input]
377
+ my_test_func
378
+
379
+ pos_arg: object
380
+ **
381
+ **kwds: dict
382
+ [clinic start generated code]*/
383
+ """
384
+ self .expect_failure (block , err , lineno = 5 )
385
+
360
386
def test_module_already_got_one (self ):
361
387
err = "Already defined module 'm'!"
362
388
block = """
@@ -748,6 +774,16 @@ def test_ignore_preprocessor_in_comments(self):
748
774
""" )
749
775
self .clinic .parse (raw )
750
776
777
+ def test_var_keyword_non_dict (self ):
778
+ err = "'var_keyword_object' is not a valid converter"
779
+ block = """
780
+ /*[clinic input]
781
+ my_test_func
782
+
783
+ **kwds: object
784
+ [clinic start generated code]*/
785
+ """
786
+ self .expect_failure (block , err , lineno = 4 )
751
787
752
788
class ParseFileUnitTest (TestCase ):
753
789
def expect_parsing_failure (
@@ -1608,6 +1644,11 @@ def test_disallowed_grouping__must_be_position_only(self):
1608
1644
[
1609
1645
a: object
1610
1646
]
1647
+ """ , """
1648
+ with_kwds
1649
+ [
1650
+ **kwds: dict
1651
+ ]
1611
1652
""" )
1612
1653
err = (
1613
1654
"You cannot use optional groups ('[' and ']') unless all "
@@ -1991,6 +2032,44 @@ def test_slash_after_vararg(self):
1991
2032
err = "Function 'bar': '/' must precede '*'"
1992
2033
self .expect_failure (block , err )
1993
2034
2035
+ def test_slash_after_var_keyword (self ):
2036
+ block = """
2037
+ module foo
2038
+ foo.bar
2039
+ x: int
2040
+ y: int
2041
+ **kwds: dict
2042
+ z: int
2043
+ /
2044
+ """
2045
+ err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'"
2046
+ self .expect_failure (block , err )
2047
+
2048
+ def test_star_after_var_keyword (self ):
2049
+ block = """
2050
+ module foo
2051
+ foo.bar
2052
+ x: int
2053
+ y: int
2054
+ **kwds: dict
2055
+ z: int
2056
+ *
2057
+ """
2058
+ err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'"
2059
+ self .expect_failure (block , err )
2060
+
2061
+ def test_parameter_after_var_keyword (self ):
2062
+ block = """
2063
+ module foo
2064
+ foo.bar
2065
+ x: int
2066
+ y: int
2067
+ **kwds: dict
2068
+ z: int
2069
+ """
2070
+ err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'"
2071
+ self .expect_failure (block , err )
2072
+
1994
2073
def test_depr_star_must_come_after_slash (self ):
1995
2074
block = """
1996
2075
module foo
@@ -2079,6 +2158,16 @@ def test_parameters_no_more_than_one_vararg(self):
2079
2158
"""
2080
2159
self .expect_failure (block , err , lineno = 3 )
2081
2160
2161
+ def test_parameters_no_more_than_one_var_keyword (self ):
2162
+ err = "Encountered parameter line when not expecting parameters: **var_keyword_2: dict"
2163
+ block = """
2164
+ module foo
2165
+ foo.bar
2166
+ **var_keyword_1: dict
2167
+ **var_keyword_2: dict
2168
+ """
2169
+ self .expect_failure (block , err , lineno = 3 )
2170
+
2082
2171
def test_function_not_at_column_0 (self ):
2083
2172
function = self .parse_function ("""
2084
2173
module foo
@@ -2513,6 +2602,14 @@ def test_vararg_cannot_take_default_value(self):
2513
2602
"""
2514
2603
self .expect_failure (block , err , lineno = 1 )
2515
2604
2605
+ def test_var_keyword_cannot_take_default_value (self ):
2606
+ err = "Function 'fn' has an invalid parameter declaration:"
2607
+ block = """
2608
+ fn
2609
+ **kwds: dict = None
2610
+ """
2611
+ self .expect_failure (block , err , lineno = 1 )
2612
+
2516
2613
def test_default_is_not_of_correct_type (self ):
2517
2614
err = ("int_converter: default value 2.5 for field 'a' "
2518
2615
"is not of type 'int'" )
@@ -2610,6 +2707,43 @@ def test_disallow_defining_class_at_module_level(self):
2610
2707
"""
2611
2708
self .expect_failure (block , err , lineno = 2 )
2612
2709
2710
+ def test_var_keyword_with_pos_or_kw (self ):
2711
+ block = """
2712
+ module foo
2713
+ foo.bar
2714
+ x: int
2715
+ **kwds: dict
2716
+ """
2717
+ err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'"
2718
+ self .expect_failure (block , err )
2719
+
2720
+ def test_var_keyword_with_kw_only (self ):
2721
+ block = """
2722
+ module foo
2723
+ foo.bar
2724
+ x: int
2725
+ /
2726
+ *
2727
+ y: int
2728
+ **kwds: dict
2729
+ """
2730
+ err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'"
2731
+ self .expect_failure (block , err )
2732
+
2733
+ def test_var_keyword_with_pos_or_kw_and_kw_only (self ):
2734
+ block = """
2735
+ module foo
2736
+ foo.bar
2737
+ x: int
2738
+ /
2739
+ y: int
2740
+ *
2741
+ z: int
2742
+ **kwds: dict
2743
+ """
2744
+ err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'"
2745
+ self .expect_failure (block , err )
2746
+
2613
2747
def test_allow_negative_accepted_by_py_ssize_t_converter_only (self ):
2614
2748
errmsg = re .escape ("converter_init() got an unexpected keyword argument 'allow_negative'" )
2615
2749
unsupported_converters = [converter_name for converter_name in converters .keys ()
@@ -3954,6 +4088,49 @@ def test_depr_multi(self):
3954
4088
check ("a" , b = "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" )
3955
4089
self .assertRaises (TypeError , fn , a = "a" , b = "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" )
3956
4090
4091
+ def test_lone_kwds (self ):
4092
+ with self .assertRaises (TypeError ):
4093
+ ac_tester .lone_kwds (1 , 2 )
4094
+ self .assertEqual (ac_tester .lone_kwds (), ({},))
4095
+ self .assertEqual (ac_tester .lone_kwds (y = 'y' ), ({'y' : 'y' },))
4096
+ kwds = {'y' : 'y' , 'z' : 'z' }
4097
+ self .assertEqual (ac_tester .lone_kwds (y = 'y' , z = 'z' ), (kwds ,))
4098
+ self .assertEqual (ac_tester .lone_kwds (** kwds ), (kwds ,))
4099
+
4100
+ def test_kwds_with_pos_only (self ):
4101
+ with self .assertRaises (TypeError ):
4102
+ ac_tester .kwds_with_pos_only ()
4103
+ with self .assertRaises (TypeError ):
4104
+ ac_tester .kwds_with_pos_only (y = 'y' )
4105
+ with self .assertRaises (TypeError ):
4106
+ ac_tester .kwds_with_pos_only (1 , y = 'y' )
4107
+ self .assertEqual (ac_tester .kwds_with_pos_only (1 , 2 ), (1 , 2 , {}))
4108
+ self .assertEqual (ac_tester .kwds_with_pos_only (1 , 2 , y = 'y' ), (1 , 2 , {'y' : 'y' }))
4109
+ kwds = {'y' : 'y' , 'z' : 'z' }
4110
+ self .assertEqual (ac_tester .kwds_with_pos_only (1 , 2 , y = 'y' , z = 'z' ), (1 , 2 , kwds ))
4111
+ self .assertEqual (ac_tester .kwds_with_pos_only (1 , 2 , ** kwds ), (1 , 2 , kwds ))
4112
+
4113
+ def test_kwds_with_stararg (self ):
4114
+ self .assertEqual (ac_tester .kwds_with_stararg (), ((), {}))
4115
+ self .assertEqual (ac_tester .kwds_with_stararg (1 , 2 ), ((1 , 2 ), {}))
4116
+ self .assertEqual (ac_tester .kwds_with_stararg (y = 'y' ), ((), {'y' : 'y' }))
4117
+ args = (1 , 2 )
4118
+ kwds = {'y' : 'y' , 'z' : 'z' }
4119
+ self .assertEqual (ac_tester .kwds_with_stararg (1 , 2 , y = 'y' , z = 'z' ), (args , kwds ))
4120
+ self .assertEqual (ac_tester .kwds_with_stararg (* args , ** kwds ), (args , kwds ))
4121
+
4122
+ def test_kwds_with_pos_only_and_stararg (self ):
4123
+ with self .assertRaises (TypeError ):
4124
+ ac_tester .kwds_with_pos_only_and_stararg ()
4125
+ with self .assertRaises (TypeError ):
4126
+ ac_tester .kwds_with_pos_only_and_stararg (y = 'y' )
4127
+ self .assertEqual (ac_tester .kwds_with_pos_only_and_stararg (1 , 2 ), (1 , 2 , (), {}))
4128
+ self .assertEqual (ac_tester .kwds_with_pos_only_and_stararg (1 , 2 , y = 'y' ), (1 , 2 , (), {'y' : 'y' }))
4129
+ args = ('lobster' , 'thermidor' )
4130
+ kwds = {'y' : 'y' , 'z' : 'z' }
4131
+ self .assertEqual (ac_tester .kwds_with_pos_only_and_stararg (1 , 2 , 'lobster' , 'thermidor' , y = 'y' , z = 'z' ), (1 , 2 , args , kwds ))
4132
+ self .assertEqual (ac_tester .kwds_with_pos_only_and_stararg (1 , 2 , * args , ** kwds ), (1 , 2 , args , kwds ))
4133
+
3957
4134
3958
4135
class LimitedCAPIOutputTests (unittest .TestCase ):
3959
4136
0 commit comments