Skip to content

Commit

Permalink
PEP 641: Use an underscore in the version portion of Python 3.10 comp…
Browse files Browse the repository at this point in the history
…atibility tag

Regardless of the py_version_nodot variable.

See https://www.python.org/dev/peps/pep-0641/
See python/cpython#22858 (comment)
  • Loading branch information
hroncok committed Nov 24, 2020
1 parent b32f744 commit 6f862cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
13 changes: 6 additions & 7 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
25 changes: 7 additions & 18 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6f862cd

Please sign in to comment.