mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
Correctly parse 2-digit minor versions (py3.10)
This commit is contained in:
committed by
Dave Halter
parent
caadf3bf4c
commit
34b8b7dd79
@@ -50,6 +50,7 @@ Daniel Fiterman (@dfit99) <fitermandaniel2@gmail.com>
|
|||||||
Simon Ruggier (@sruggier)
|
Simon Ruggier (@sruggier)
|
||||||
Élie Gouzien (@ElieGouzien)
|
Élie Gouzien (@ElieGouzien)
|
||||||
Tim Gates (@timgates42) <tim.gates@iress.com>
|
Tim Gates (@timgates42) <tim.gates@iress.com>
|
||||||
|
Batuhan Taskaya (@isidentical) <isidentical@gmail.com>
|
||||||
|
|
||||||
|
|
||||||
Note: (@user) means a github user name.
|
Note: (@user) means a github user name.
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ def version_info():
|
|||||||
|
|
||||||
|
|
||||||
def _parse_version(version):
|
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:
|
if match is None:
|
||||||
raise ValueError('The given version is not in the right format. '
|
raise ValueError('The given version is not in the right format. '
|
||||||
'Use something like "3.8" or "3".')
|
'Use something like "3.8" or "3".')
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
from codecs import BOM_UTF8
|
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 parso
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -77,3 +82,18 @@ def test_bytes_to_unicode_failing_encoding(code, errors):
|
|||||||
python_bytes_to_unicode(code, errors=errors)
|
python_bytes_to_unicode(code, errors=errors)
|
||||||
else:
|
else:
|
||||||
python_bytes_to_unicode(code, errors=errors)
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user