Skip to content

Commit 5f3406f

Browse files
Proof of Concept
1 parent 71868a0 commit 5f3406f

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

Modules/_sqlite/clinic/module.c.h

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/module.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ _sqlite3.connect as pysqlite_connect
5252
isolation_level: object = NULL
5353
check_same_thread: bool(accept={int}) = True
5454
factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType
55+
x
5556
cached_statements: int = 128
5657
uri: bool = False
5758
@@ -66,7 +67,7 @@ pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
6667
int detect_types, PyObject *isolation_level,
6768
int check_same_thread, PyObject *factory,
6869
int cached_statements, int uri)
69-
/*[clinic end generated code: output=450ac9078b4868bb input=e16914663ddf93ce]*/
70+
/*[clinic end generated code: output=450ac9078b4868bb input=57d6a8263524a38f]*/
7071
{
7172
if (isolation_level == NULL) {
7273
isolation_level = PyUnicode_FromString("");

Tools/clinic/clinic.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,16 @@ def parser_body(prototype, *fields, declarations=''):
10501050
goto %s;
10511051
}}
10521052
""" % 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))
10531063
if i + 1 == len(parameters):
10541064
parser_code.append(normalize_snippet(parsearg, indent=4))
10551065
else:
@@ -2372,7 +2382,7 @@ class Parameter:
23722382

23732383
def __init__(self, name, kind, *, default=inspect.Parameter.empty,
23742384
function, converter, annotation=inspect.Parameter.empty,
2375-
docstring=None, group=0):
2385+
docstring=None, group=0, deprecated_positional=False):
23762386
self.name = name
23772387
self.kind = kind
23782388
self.default = default
@@ -2381,6 +2391,7 @@ def __init__(self, name, kind, *, default=inspect.Parameter.empty,
23812391
self.annotation = annotation
23822392
self.docstring = docstring or ''
23832393
self.group = group
2394+
self.deprecated_positional = deprecated_positional
23842395

23852396
def __repr__(self):
23862397
return '<clinic.Parameter ' + self.name + '>'
@@ -4028,6 +4039,7 @@ def reset(self):
40284039
self.parameter_indent = None
40294040
self.keyword_only = False
40304041
self.positional_only = False
4042+
self.deprecated_positional = False
40314043
self.group = 0
40324044
self.parameter_state = self.ps_start
40334045
self.seen_positional_with_default = False
@@ -4468,7 +4480,7 @@ def state_parameter(self, line):
44684480

44694481
line = line.lstrip()
44704482

4471-
if line in ('*', '/', '[', ']'):
4483+
if line in ('x', '*', '/', '[', ']'):
44724484
self.parse_special_symbol(line)
44734485
return
44744486

@@ -4708,7 +4720,8 @@ def bad_node(self, node):
47084720
fail("A 'defining_class' parameter, if specified, must either be the first thing in the parameter block, or come just after 'self'.")
47094721

47104722

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)
47124725

47134726
if parameter_name in self.function.parameters:
47144727
fail("You can't have two parameters named " + repr(parameter_name) + "!")
@@ -4736,6 +4749,12 @@ def parse_converter(self, annotation):
47364749
return name, False, kwargs
47374750

47384751
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
47394758
if symbol == '*':
47404759
if self.keyword_only:
47414760
fail("Function " + self.function.name + " uses '*' more than once.")
@@ -5101,6 +5120,8 @@ def state_terminal(self, line):
51015120
if no_parameter_after_star:
51025121
fail("Function " + self.function.name + " specifies '*' without any parameters afterwards.")
51035122

5123+
# EAA: Add check here
5124+
51045125
# remove trailing whitespace from all parameter docstrings
51055126
for name, value in self.function.parameters.items():
51065127
if not value:

0 commit comments

Comments
 (0)