diff --git a/AUTHORS.txt b/AUTHORS.txt index e5b72ca..682b0fc 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -50,6 +50,7 @@ Daniel Fiterman (@dfit99) Simon Ruggier (@sruggier) Élie Gouzien (@ElieGouzien) Tim Gates (@timgates42) +Batuhan Taskaya (@isidentical) Note: (@user) means a github user name. diff --git a/parso/utils.py b/parso/utils.py index 1485928..76333a0 100644 --- a/parso/utils.py +++ b/parso/utils.py @@ -129,7 +129,7 @@ def version_info(): def _parse_version(version): - match = re.match(r'(\d+)(?:\.(\d)(?:\.\d+)?)?$', version) + match = re.match(r'(\d+)(?:\.(\d{1,2})(?:\.\d+)?)?$', version) if match is None: raise ValueError('The given version is not in the right format. ' 'Use something like "3.8" or "3".') diff --git a/test/test_utils.py b/test/test_utils.py index 44a4ce4..1238e72 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,6 +1,11 @@ from codecs import BOM_UTF8 -from parso.utils import split_lines, python_bytes_to_unicode +from parso.utils import ( + split_lines, + parse_version_string, + python_bytes_to_unicode, +) + import parso import pytest @@ -77,3 +82,18 @@ def test_bytes_to_unicode_failing_encoding(code, errors): python_bytes_to_unicode(code, errors=errors) else: python_bytes_to_unicode(code, errors=errors) + +@pytest.mark.parametrize( + ('version_str', 'version'), [ + ('3', (3,)), + ('3.6', (3, 6)), + ('3.6.10', (3, 6)), + ('3.10', (3, 10)), + ] +) +def test_parse_version_string(version_str, version): + parsed_version = parse_version_string(version_str) + if len(version) == 1: + assert parsed_version[0] == version[0] + else: + assert parsed_version == version