Skip to content

Commit

Permalink
pythongh-113336: Remove the 'version' directive from Argument Clinic (p…
Browse files Browse the repository at this point in the history
…ython#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.
  • Loading branch information
erlend-aasland authored and ryan-duve committed Dec 26, 2023
1 parent 7255950 commit 8c989c8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 117 deletions.
65 changes: 0 additions & 65 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from test.support.os_helper import TESTFN, unlink
from textwrap import dedent
from unittest import TestCase
import contextlib
import inspect
import os.path
import re
Expand Down Expand Up @@ -264,70 +263,6 @@ def converter_init(self):
)
self.expect_failure(raw, err)

@staticmethod
@contextlib.contextmanager
def _clinic_version(new_version):
"""Helper for test_version_*() tests"""
_saved = clinic.version
clinic.version = new_version
try:
yield
finally:
clinic.version = _saved

def test_version_directive(self):
dataset = (
# (clinic version, required version)
('3', '2'), # required version < clinic version
('3.1', '3.0'), # required version < clinic version
('1.2b0', '1.2a7'), # required version < clinic version
('5', '5'), # required version == clinic version
('6.1', '6.1'), # required version == clinic version
('1.2b3', '1.2b3'), # required version == clinic version
)
for clinic_version, required_version in dataset:
with self.subTest(clinic_version=clinic_version,
required_version=required_version):
with self._clinic_version(clinic_version):
block = dedent(f"""
/*[clinic input]
version {required_version}
[clinic start generated code]*/
""")
self.clinic.parse(block)

def test_version_directive_insufficient_version(self):
with self._clinic_version('4'):
err = (
"Insufficient Clinic version!\n"
" Version: 4\n"
" Required: 5"
)
block = """
/*[clinic input]
version 5
[clinic start generated code]*/
"""
self.expect_failure(block, err)

def test_version_directive_illegal_char(self):
err = "Illegal character 'v' in version string 'v5'"
block = """
/*[clinic input]
version v5
[clinic start generated code]*/
"""
self.expect_failure(block, err)

def test_version_directive_unsupported_string(self):
err = "Unsupported version string: '.-'"
block = """
/*[clinic input]
version .-
[clinic start generated code]*/
"""
self.expect_failure(block, err)

def test_clone_mismatch(self):
err = "'kind' of function and cloned function don't match!"
block = """
Expand Down
52 changes: 0 additions & 52 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
# and keyword-only
#

version = '1'

NO_VARARG = "PY_SSIZE_T_MAX"
CLINIC_PREFIX = "__clinic_"
CLINIC_PREFIXED_ARGS = {
Expand Down Expand Up @@ -375,49 +373,6 @@ def pprint_words(items: list[str]) -> str:
return ", ".join(items[:-1]) + " and " + items[-1]


def version_splitter(s: str) -> tuple[int, ...]:
"""Splits a version string into a tuple of integers.
The following ASCII characters are allowed, and employ
the following conversions:
a -> -3
b -> -2
c -> -1
(This permits Python-style version strings such as "1.4b3".)
"""
version: list[int] = []
accumulator: list[str] = []
def flush() -> None:
if not accumulator:
fail(f'Unsupported version string: {s!r}')
version.append(int(''.join(accumulator)))
accumulator.clear()

for c in s:
if c.isdigit():
accumulator.append(c)
elif c == '.':
flush()
elif c in 'abc':
flush()
version.append('abc'.index(c) - 3)
else:
fail(f'Illegal character {c!r} in version string {s!r}')
flush()
return tuple(version)

def version_comparator(version1: str, version2: str) -> Literal[-1, 0, 1]:
iterator = itertools.zip_longest(
version_splitter(version1), version_splitter(version2), fillvalue=0
)
for a, b in iterator:
if a < b:
return -1
if a > b:
return 1
return 0


class CRenderData:
def __init__(self) -> None:

Expand Down Expand Up @@ -5262,13 +5217,6 @@ def reset(self) -> None:
self.critical_section = False
self.target_critical_section = []

def directive_version(self, required: str) -> None:
global version
if version_comparator(version, required) < 0:
fail("Insufficient Clinic version!\n"
f" Version: {version}\n"
f" Required: {required}")

def directive_module(self, name: str) -> None:
fields = name.split('.')[:-1]
module, cls = self.clinic._module_and_class(fields)
Expand Down

0 comments on commit 8c989c8

Please sign in to comment.