From 6f862cdf60fec2f58796d2d8dcf891cc55721504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 24 Nov 2020 12:03:14 +0100 Subject: [PATCH] PEP 641: Use an underscore in the version portion of Python 3.10 compatibility tag Regardless of the py_version_nodot variable. See https://www.python.org/dev/peps/pep-0641/ See https://github.com/python/cpython/pull/22858#issuecomment-720608651 --- packaging/tags.py | 13 ++++++------- tests/test_tags.py | 25 +++++++------------------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index 289ed5c1..8e695c7b 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -782,14 +782,13 @@ def interpreter_name(): def interpreter_version(**kwargs): # type: (bool) -> str """ - Returns the version of the running interpreter. + Returns the version of the running interpreter for the wheel tag. + + See https://www.python.org/dev/peps/pep-0641/ """ - warn = _warn_keyword_parameter("interpreter_version", kwargs) - version = _get_config_var("py_version_nodot", warn=warn) - if version: - version = str(version) - else: - version = _version_nodot(sys.version_info[:2]) + # warn kw only parameter is unused, kept for backwards compatibility + _warn_keyword_parameter("interpreter_version", kwargs) + version = _version_nodot(sys.version_info[:2]) return version diff --git a/tests/test_tags.py b/tests/test_tags.py index e9ea3343..13121b3a 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -172,24 +172,13 @@ def test_interpreter_short_names(self, mock_interpreter_name, monkeypatch): class TestInterpreterVersion: - def test_warn(self, monkeypatch): - class MockConfigVar(object): - def __init__(self, return_): - self.warn = None - self._return = return_ - - def __call__(self, name, warn): - self.warn = warn - return self._return - - mock_config_var = MockConfigVar("38") - monkeypatch.setattr(tags, "_get_config_var", mock_config_var) - tags.interpreter_version(warn=True) - assert mock_config_var.warn - - def test_python_version_nodot(self, monkeypatch): - monkeypatch.setattr(tags, "_get_config_var", lambda var, warn: "NN") - assert tags.interpreter_version() == "NN" + def test_python_version_nodot_underscore(self, monkeypatch): + monkeypatch.setattr(sys, "version_info", (3, 20, 12)) + assert tags.interpreter_version() == "3_20" + + def test_python_version_nodot_no_underscore(self, monkeypatch): + monkeypatch.setattr(sys, "version_info", (3, 9, 12)) + assert tags.interpreter_version() == "39" @pytest.mark.parametrize( "version_info,version_str",