mirror of https://github.com/python/cpython
gh-113336: Remove the 'version' directive from Argument Clinic (#113341)
The 'version' directive was introduced with gh-63929 in Nov 2013. It has not been in use in the CPython code base, and the 'version' variable has never been bumped.
This commit is contained in:
parent
4b90b5d857
commit
fae096cd4b
|
@ -8,7 +8,6 @@ from test.support import os_helper
|
||||||
from test.support.os_helper import TESTFN, unlink
|
from test.support.os_helper import TESTFN, unlink
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
import contextlib
|
|
||||||
import inspect
|
import inspect
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
@ -264,70 +263,6 @@ class ClinicWholeFileTest(TestCase):
|
||||||
)
|
)
|
||||||
self.expect_failure(raw, err)
|
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):
|
def test_clone_mismatch(self):
|
||||||
err = "'kind' of function and cloned function don't match!"
|
err = "'kind' of function and cloned function don't match!"
|
||||||
block = """
|
block = """
|
||||||
|
|
|
@ -61,8 +61,6 @@ from typing import (
|
||||||
# and keyword-only
|
# and keyword-only
|
||||||
#
|
#
|
||||||
|
|
||||||
version = '1'
|
|
||||||
|
|
||||||
NO_VARARG = "PY_SSIZE_T_MAX"
|
NO_VARARG = "PY_SSIZE_T_MAX"
|
||||||
CLINIC_PREFIX = "__clinic_"
|
CLINIC_PREFIX = "__clinic_"
|
||||||
CLINIC_PREFIXED_ARGS = {
|
CLINIC_PREFIXED_ARGS = {
|
||||||
|
@ -375,49 +373,6 @@ def pprint_words(items: list[str]) -> str:
|
||||||
return ", ".join(items[:-1]) + " and " + items[-1]
|
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:
|
class CRenderData:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
|
||||||
|
@ -5262,13 +5217,6 @@ class DSLParser:
|
||||||
self.critical_section = False
|
self.critical_section = False
|
||||||
self.target_critical_section = []
|
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:
|
def directive_module(self, name: str) -> None:
|
||||||
fields = name.split('.')[:-1]
|
fields = name.split('.')[:-1]
|
||||||
module, cls = self.clinic._module_and_class(fields)
|
module, cls = self.clinic._module_and_class(fields)
|
||||||
|
|
Loading…
Reference in New Issue