Skip to content

Commit bcd732b

Browse files
erlend-aaslandkulikjak
authored andcommitted
pythongh-113336: Remove the 'version' directive from Argument Clinic (python#113341)
The 'version' directive was introduced with pythongh-63929 in Nov 2013. It has not been in use in the CPython code base, and the 'version' variable has never been bumped.
1 parent 3cc2337 commit bcd732b

File tree

2 files changed

+0
-117
lines changed

2 files changed

+0
-117
lines changed

Lib/test/test_clinic.py

-65
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from test.support.os_helper import TESTFN, unlink
99
from textwrap import dedent
1010
from unittest import TestCase
11-
import contextlib
1211
import inspect
1312
import os.path
1413
import re
@@ -264,70 +263,6 @@ def converter_init(self):
264263
)
265264
self.expect_failure(raw, err)
266265

267-
@staticmethod
268-
@contextlib.contextmanager
269-
def _clinic_version(new_version):
270-
"""Helper for test_version_*() tests"""
271-
_saved = clinic.version
272-
clinic.version = new_version
273-
try:
274-
yield
275-
finally:
276-
clinic.version = _saved
277-
278-
def test_version_directive(self):
279-
dataset = (
280-
# (clinic version, required version)
281-
('3', '2'), # required version < clinic version
282-
('3.1', '3.0'), # required version < clinic version
283-
('1.2b0', '1.2a7'), # required version < clinic version
284-
('5', '5'), # required version == clinic version
285-
('6.1', '6.1'), # required version == clinic version
286-
('1.2b3', '1.2b3'), # required version == clinic version
287-
)
288-
for clinic_version, required_version in dataset:
289-
with self.subTest(clinic_version=clinic_version,
290-
required_version=required_version):
291-
with self._clinic_version(clinic_version):
292-
block = dedent(f"""
293-
/*[clinic input]
294-
version {required_version}
295-
[clinic start generated code]*/
296-
""")
297-
self.clinic.parse(block)
298-
299-
def test_version_directive_insufficient_version(self):
300-
with self._clinic_version('4'):
301-
err = (
302-
"Insufficient Clinic version!\n"
303-
" Version: 4\n"
304-
" Required: 5"
305-
)
306-
block = """
307-
/*[clinic input]
308-
version 5
309-
[clinic start generated code]*/
310-
"""
311-
self.expect_failure(block, err)
312-
313-
def test_version_directive_illegal_char(self):
314-
err = "Illegal character 'v' in version string 'v5'"
315-
block = """
316-
/*[clinic input]
317-
version v5
318-
[clinic start generated code]*/
319-
"""
320-
self.expect_failure(block, err)
321-
322-
def test_version_directive_unsupported_string(self):
323-
err = "Unsupported version string: '.-'"
324-
block = """
325-
/*[clinic input]
326-
version .-
327-
[clinic start generated code]*/
328-
"""
329-
self.expect_failure(block, err)
330-
331266
def test_clone_mismatch(self):
332267
err = "'kind' of function and cloned function don't match!"
333268
block = """

Tools/clinic/clinic.py

-52
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161
# and keyword-only
6262
#
6363

64-
version = '1'
65-
6664
NO_VARARG = "PY_SSIZE_T_MAX"
6765
CLINIC_PREFIX = "__clinic_"
6866
CLINIC_PREFIXED_ARGS = {
@@ -375,49 +373,6 @@ def pprint_words(items: list[str]) -> str:
375373
return ", ".join(items[:-1]) + " and " + items[-1]
376374

377375

378-
def version_splitter(s: str) -> tuple[int, ...]:
379-
"""Splits a version string into a tuple of integers.
380-
381-
The following ASCII characters are allowed, and employ
382-
the following conversions:
383-
a -> -3
384-
b -> -2
385-
c -> -1
386-
(This permits Python-style version strings such as "1.4b3".)
387-
"""
388-
version: list[int] = []
389-
accumulator: list[str] = []
390-
def flush() -> None:
391-
if not accumulator:
392-
fail(f'Unsupported version string: {s!r}')
393-
version.append(int(''.join(accumulator)))
394-
accumulator.clear()
395-
396-
for c in s:
397-
if c.isdigit():
398-
accumulator.append(c)
399-
elif c == '.':
400-
flush()
401-
elif c in 'abc':
402-
flush()
403-
version.append('abc'.index(c) - 3)
404-
else:
405-
fail(f'Illegal character {c!r} in version string {s!r}')
406-
flush()
407-
return tuple(version)
408-
409-
def version_comparator(version1: str, version2: str) -> Literal[-1, 0, 1]:
410-
iterator = itertools.zip_longest(
411-
version_splitter(version1), version_splitter(version2), fillvalue=0
412-
)
413-
for a, b in iterator:
414-
if a < b:
415-
return -1
416-
if a > b:
417-
return 1
418-
return 0
419-
420-
421376
class CRenderData:
422377
def __init__(self) -> None:
423378

@@ -5262,13 +5217,6 @@ def reset(self) -> None:
52625217
self.critical_section = False
52635218
self.target_critical_section = []
52645219

5265-
def directive_version(self, required: str) -> None:
5266-
global version
5267-
if version_comparator(version, required) < 0:
5268-
fail("Insufficient Clinic version!\n"
5269-
f" Version: {version}\n"
5270-
f" Required: {required}")
5271-
52725220
def directive_module(self, name: str) -> None:
52735221
fields = name.split('.')[:-1]
52745222
module, cls = self.clinic._module_and_class(fields)

0 commit comments

Comments
 (0)