diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-04-28 21:58:38 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-04-28 22:25:13 +0200 |
commit | 0e63847122ee898e81b3258827e0c05702f68459 (patch) | |
tree | 116622b71a1b8bcfc9f3efeb7879941118e29b30 | |
parent | 24b5159e00b8a380c1776dab6ce096df7bad79b1 (diff) | |
download | pylint-git-0e63847122ee898e81b3258827e0c05702f68459.tar.gz |
Fix retrocompatbility of numversion
We need to be able to handle empty version for tests.
Closes #4420
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/__pkginfo__.py | 32 | ||||
-rw-r--r-- | tests/test_numversion.py | 26 |
3 files changed, 60 insertions, 2 deletions
@@ -9,6 +9,10 @@ Release date: 2021-04-26 .. Put new features and bugfixes here and also in 'doc/whatsnew/2.9.rst' +* numversion tuple contains integers again to fix multiple pylint's plugins that relied on it + + Closes #4420 + * Fix false-positive ``too-many-ancestors`` when inheriting from builtin classes, especially from the ``collections.abc`` module diff --git a/pylint/__pkginfo__.py b/pylint/__pkginfo__.py index 8316089ec..1a1d99dd2 100644 --- a/pylint/__pkginfo__.py +++ b/pylint/__pkginfo__.py @@ -1,5 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html # For details: https://github.com/PyCQA/pylint/blob/master/LICENSE +from typing import Tuple from pkg_resources import DistributionNotFound, get_distribution @@ -8,5 +9,32 @@ try: except DistributionNotFound: __version__ = "2.8.2+" -# Kept for compatibility reason, see https://github.com/PyCQA/pylint/issues/4399 -numversion = tuple(__version__.split(".")) + +def get_numversion_from_version(v: str) -> Tuple: + """Kept for compatibility reason + + See https://github.com/PyCQA/pylint/issues/4399 + https://github.com/PyCQA/pylint/issues/4420, + """ + v = v.replace("pylint-", "") + version = [] + for n in v.split(".")[0:3]: + try: + version.append(int(n)) + except ValueError: + num = "" + for c in n: + if c.isdigit(): + num += c + else: + break + try: + version.append(int(num)) + except ValueError: + version.append(0) + while len(version) != 3: + version.append(0) + return tuple(version) + + +numversion = get_numversion_from_version(__version__) diff --git a/tests/test_numversion.py b/tests/test_numversion.py new file mode 100644 index 000000000..d1f459a5a --- /dev/null +++ b/tests/test_numversion.py @@ -0,0 +1,26 @@ +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/master/LICENSE + +import pytest + +from pylint.__pkginfo__ import get_numversion_from_version + + +@pytest.mark.parametrize( + "version,expected_numversion", + [ + ["2.8.1", (2, 8, 1)], + ["2.8.2+", (2, 8, 2)], + ["3.0.0a0", (3, 0, 0)], + ["3..0", (3, 0, 0)], + ["1.a", (1, 0, 0)], + ["", (0, 0, 0)], + ["3.0.0b1", (3, 0, 0)], + ["3.0.0rc1", (3, 0, 0)], + ["3.0.0dev-234324234234f23abc4", (3, 0, 0)], + ["pylint-2.4.7", (2, 4, 7)], + ["2.8.3.dev3+g28c093c2.d20210428", (2, 8, 3)], + ], +) +def test_numversion(version, expected_numversion): + assert get_numversion_from_version(version) == expected_numversion |