@@ -1050,6 +1050,16 @@ def parser_body(prototype, *fields, declarations=''):
1050
1050
goto %s;
1051
1051
}}
1052
1052
""" % add_label , indent = 4 ))
1053
+ if p .deprecated_positional :
1054
+ parser_code .append (normalize_snippet ("""
1055
+ if (nargs == %s) {{
1056
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
1057
+ "Using '%s' as positional argument is deprecated", 2))
1058
+ {{
1059
+ goto exit;
1060
+ }}
1061
+ }}
1062
+ """ % (str (i + 1 ), p .name ), indent = 4 ))
1053
1063
if i + 1 == len (parameters ):
1054
1064
parser_code .append (normalize_snippet (parsearg , indent = 4 ))
1055
1065
else :
@@ -2372,7 +2382,7 @@ class Parameter:
2372
2382
2373
2383
def __init__ (self , name , kind , * , default = inspect .Parameter .empty ,
2374
2384
function , converter , annotation = inspect .Parameter .empty ,
2375
- docstring = None , group = 0 ):
2385
+ docstring = None , group = 0 , deprecated_positional = False ):
2376
2386
self .name = name
2377
2387
self .kind = kind
2378
2388
self .default = default
@@ -2381,6 +2391,7 @@ def __init__(self, name, kind, *, default=inspect.Parameter.empty,
2381
2391
self .annotation = annotation
2382
2392
self .docstring = docstring or ''
2383
2393
self .group = group
2394
+ self .deprecated_positional = deprecated_positional
2384
2395
2385
2396
def __repr__ (self ):
2386
2397
return '<clinic.Parameter ' + self .name + '>'
@@ -4028,6 +4039,7 @@ def reset(self):
4028
4039
self .parameter_indent = None
4029
4040
self .keyword_only = False
4030
4041
self .positional_only = False
4042
+ self .deprecated_positional = False
4031
4043
self .group = 0
4032
4044
self .parameter_state = self .ps_start
4033
4045
self .seen_positional_with_default = False
@@ -4468,7 +4480,7 @@ def state_parameter(self, line):
4468
4480
4469
4481
line = line .lstrip ()
4470
4482
4471
- if line in ('*' , '/' , '[' , ']' ):
4483
+ if line in ('x' , ' *' , '/' , '[' , ']' ):
4472
4484
self .parse_special_symbol (line )
4473
4485
return
4474
4486
@@ -4708,7 +4720,8 @@ def bad_node(self, node):
4708
4720
fail ("A 'defining_class' parameter, if specified, must either be the first thing in the parameter block, or come just after 'self'." )
4709
4721
4710
4722
4711
- p = Parameter (parameter_name , kind , function = self .function , converter = converter , default = value , group = self .group )
4723
+ p = Parameter (parameter_name , kind , function = self .function , converter = converter , default = value , group = self .group ,
4724
+ deprecated_positional = self .deprecated_positional )
4712
4725
4713
4726
if parameter_name in self .function .parameters :
4714
4727
fail ("You can't have two parameters named " + repr (parameter_name ) + "!" )
@@ -4736,6 +4749,12 @@ def parse_converter(self, annotation):
4736
4749
return name , False , kwargs
4737
4750
4738
4751
def parse_special_symbol (self , symbol ):
4752
+ if symbol == 'x' :
4753
+ if self .keyword_only :
4754
+ fail ("Function " + self .function .name + ": 'x' must come before '*'" )
4755
+ if self .deprecated_positional :
4756
+ fail ("Function " + self .function .name + " uses 'x' more than once." )
4757
+ self .deprecated_positional = True
4739
4758
if symbol == '*' :
4740
4759
if self .keyword_only :
4741
4760
fail ("Function " + self .function .name + " uses '*' more than once." )
@@ -5101,6 +5120,8 @@ def state_terminal(self, line):
5101
5120
if no_parameter_after_star :
5102
5121
fail ("Function " + self .function .name + " specifies '*' without any parameters afterwards." )
5103
5122
5123
+ # EAA: Add check here
5124
+
5104
5125
# remove trailing whitespace from all parameter docstrings
5105
5126
for name , value in self .function .parameters .items ():
5106
5127
if not value :
0 commit comments