Repository: peterbe/hashin

Issue:
Running hashin with Python versions >= 3.10 raises PackageError('No releases can be found....')
The issue seems to stem from this piece of code.

```python
def expand_python_version(version):
    if not re.match(r"^\d\.\d$", version):
        return [version]
```

The above regular expression assumes the minor version number can have only a single digit. Therefore the result will be incorrect for Python versions >= 3.10.

We probably want to change it to

```python
    if not re.match(r"^\d\.\d*\d$", version)
```

Hints from issue comments:
@hartwork: For a reproducer:

```Dockerfile
FROM python:3.10
RUN pip3 install hashin \
        && \
    touch requirements.txt \
        && \
    hashin -r requirements.txt -p 3.10 hashin
```

It takes:
- a) calling function `expand_python_version` from third party Python code or
- b) use of argument `-p PYTHON_VERSION` on the command line


Solution patch:
diff --git a/hashin.py b/hashin.py
index 284af3b..ecef05f 100755
--- a/hashin.py
+++ b/hashin.py
@@ -459,9 +459,9 @@ def expand_python_version(version):
     Expand Python versions to all identifiers used on PyPI.
 
     >>> expand_python_version('3.5')
-    ['3.5', 'py3', 'py2.py3', 'cp35']
+    ['3.5', 'cp35', 'py2.py3', 'py3', 'py3.5', 'py35', 'source']
     """
-    if not re.match(r"^\d\.\d$", version):
+    if not re.match(r"^\d\.\d{1,2}$", version):
         return [version]
 
     major, minor = version.split(".")


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index d17ebbf..90804c4 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -2189,6 +2189,26 @@ def test_expand_python_version():
         "source",
     ]
 
+    assert sorted(hashin.expand_python_version("3.10")) == [
+        "3.10",
+        "cp310",
+        "py2.py3",
+        "py3",
+        "py3.10",
+        "py310",
+        "source",
+    ]
+
+    assert sorted(hashin.expand_python_version("3.12")) == [
+        "3.12",
+        "cp312",
+        "py2.py3",
+        "py3",
+        "py3.12",
+        "py312",
+        "source",
+    ]
+
 
 def test_get_package_hashes(murlopen):
     def mocked_get(url, **options):