Repository: ludeeus/awesomeversion (language: python)

Issue:
Version comparison throws
### The problem

Coming from this issue with update entities in HA (https://github.com/home-assistant/core/issues/120264). awesomeversion can't compare the version strings `v3.6-rc2` and `v3.4-rc5`

### Operating system

Win/HAOS/WSL

### Python version

3.11

### Problem-relevant code

```python
>>> AwesomeVersion("v3.4-rc5") > "v3.6-rc2"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zweckj/dev/home-assistant-core/venv/lib/python3.12/site-packages/awesomeversion/awesomeversion.py", line 188, in __gt__
    raise AwesomeVersionCompareException(
awesomeversion.exceptions.AwesomeVersionCompareException: Can't compare <unknown v3.4-rc5> and <unknown v3.6-rc2>
```


### Traceback/Error logs

_No response_

### Additional information

_No response_


Discussion / hints:
Please provide the details of what version strategy this is.
 @ludeeus I have no idea tbh. The strings are taken from their API as is. I'm not sure I understand the regexes. I normally use `packaging.version` for version checks (which handles that string just fine), just ended up at `awesomeversion` because of the aforementioned HA bug.

Fix patch:
diff --git a/awesomeversion/utils/regex.py b/awesomeversion/utils/regex.py
index e64ee3d..ace2410 100644
--- a/awesomeversion/utils/regex.py
+++ b/awesomeversion/utils/regex.py
@@ -16,8 +16,10 @@
     r"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"
 )
 RE_PEP440 = (
-    r"([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)"
-    r"(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?(\.rc(0|[1-9][0-9]*))?"
+    r"([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*"  # Main segment
+    r"([-_\.]?(alpha|beta|c|pre|preview|a|b|rc)(0|[1-9][0-9]*))?"  # Pre-release segment
+    r"([-_\.]?(post|r|rev)(0|[1-9][0-9]*))?"  # Post-release segment
+    r"([-_\.]?(d|dev)(0|[1-9][0-9]*))?"  # Development release segment
 )
 RE_BUILDVER = r"\d+"
 


Test patch:
diff --git a/tests/issues/test_issue333.py b/tests/issues/test_issue333.py
new file mode 100644
index 0000000..d0d15ea
--- /dev/null
+++ b/tests/issues/test_issue333.py
@@ -0,0 +1,13 @@
+"""Test for issue #333."""
+
+# https://github.com/ludeeus/awesomeversion/issues/333
+from awesomeversion import AwesomeVersion
+from awesomeversion.strategy import AwesomeVersionStrategy
+
+
+def test() -> None:
+    """Test for issue #333."""
+    version = AwesomeVersion("v3.4-rc5")
+    assert version < "v3.6-rc2"
+    assert version.release_candidate
+    assert version.strategy != AwesomeVersionStrategy.UNKNOWN
diff --git a/tests/snapshots/PEP 440/1-dev1.json b/tests/snapshots/PEP 440/1-dev1.json
new file mode 100644
index 0000000..7bdc2c8
--- /dev/null
+++ b/tests/snapshots/PEP 440/1-dev1.json
@@ -0,0 +1,19 @@
+{
+    "alpha": false,
+    "beta": false,
+    "dev": true,
+    "major": "1",
+    "micro": null,
+    "minor": null,
+    "modifier_type": "dev",
+    "modifier": "dev1",
+    "patch": null,
+    "prefix": null,
+    "release_candidate": false,
+    "sections": 1,
+    "simple": false,
+    "strategy": "PEP 440",
+    "string": "1-dev1",
+    "valid": true,
+    "year": "1"
+}
\ No newline at end of file
diff --git a/tests/snapshots/unknown/1.0.0beta0.json b/tests/snapshots/PEP 440/1.0.0beta0.json
similarity index 62%
rename from tests/snapshots/unknown/1.0.0beta0.json
rename to tests/snapshots/PEP 440/1.0.0beta0.json
index be15b4f..ace9662 100644
--- a/tests/snapshots/unknown/1.0.0beta0.json
+++ b/tests/snapshots/PEP 440/1.0.0beta0.json
@@ -2,18 +2,18 @@
     "alpha": true,
     "beta": true,
     "dev": false,
-    "major": null,
-    "micro": null,
-    "minor": null,
+    "major": "1",
+    "micro": "0",
+    "minor": "0",
     "modifier_type": "beta",
     "modifier": "beta0",
-    "patch": null,
+    "patch": "0",
     "prefix": null,
     "release_candidate": false,
     "sections": 3,
     "simple": false,
-    "strategy": "unknown",
+    "strategy": "PEP 440",
     "string": "1.0.0beta0",
-    "valid": false,
-    "year": null
+    "valid": true,
+    "year": "1"
 }
\ No newline at end of file
diff --git a/tests/snapshots/unknown/1.0.a0.json b/tests/snapshots/PEP 440/1.0.a0.json
similarity index 71%
rename from tests/snapshots/unknown/1.0.a0.json
rename to tests/snapshots/PEP 440/1.0.a0.json
index 7a5d863..0e27df3 100644
--- a/tests/snapshots/unknown/1.0.a0.json
+++ b/tests/snapshots/PEP 440/1.0.a0.json
@@ -2,9 +2,9 @@
     "alpha": true,
     "beta": false,
     "dev": false,
-    "major": null,
+    "major": "1",
     "micro": null,
-    "minor": null,
+    "minor": "0",
     "modifier_type": "a",
     "modifier": "a0",
     "patch": null,
@@ -12,8 +12,8 @@
     "release_candidate": false,
     "sections": 2,
     "simple": false,
-    "strategy": "unknown",
+    "strategy": "PEP 440",
     "string": "1.0.a0",
-    "valid": false,
-    "year": null
+    "valid": true,
+    "year": "1"
 }
\ No newline at end of file
diff --git a/tests/snapshots/unknown/1.0.alpha1.json b/tests/snapshots/PEP 440/1.0.alpha1.json
similarity index 72%
rename from tests/snapshots/unknown/1.0.alpha1.json
rename to tests/snapshots/PEP 440/1.0.alpha1.json
index 95858d6..760e890 100644
--- a/tests/snapshots/unknown/1.0.alpha1.json
+++ b/tests/snapshots/PEP 440/1.0.alpha1.json
@@ -2,9 +2,9 @@
     "alpha": true,
     "beta": false,
     "dev": false,
-    "major": null,
+    "major": "1",
     "micro": null,
-    "minor": null,
+    "minor": "0",
     "modifier_type": "alpha",
     "modifier": "alpha1",
     "patch": null,
@@ -12,8 +12,8 @@
     "release_candidate": false,
     "sections": 2,
     "simple": false,
-    "strategy": "unknown",
+    "strategy": "PEP 440",
     "string": "1.0.alpha1",
-    "valid": false,
-    "year": null
+    "valid": true,
+    "year": "1"
 }
\ No newline at end of file
diff --git a/tests/snapshots/unknown/1.0.b0.json b/tests/snapshots/PEP 440/1.0.b0.json
similarity index 71%
rename from tests/snapshots/unknown/1.0.b0.json
rename to tests/snapshots/PEP 440/1.0.b0.json
index 3a4d074..6b7cda5 100644
--- a/tests/snapshots/unknown/1.0.b0.json
+++ b/tests/snapshots/PEP 440/1.0.b0.json
@@ -2,9 +2,9 @@
     "alpha": false,
     "beta": true,
     "dev": false,
-    "major": null,
+    "major": "1",
     "micro": null,
-    "minor": null,
+    "minor": "0",
     "modifier_type": "b",
     "modifier": "b0",
     "patch": null,
@@ -12,8 +12,8 @@
     "release_candidate": false,
     "sections": 2,
     "simple": false,
-    "strategy": "unknown",
+    "strategy": "PEP 440",
     "string": "1.0.b0",
-    "valid": false,
-    "year": null
+    "valid": true,
+    "year": "1"
 }
\ No newline at end of file
diff --git a/tests/snapshots/unknown/1.0.b1.json b/tests/snapshots/PEP 440/1.0.b1.json
similarity index 71%
rename from tests/snapshots/unknown/1.0.b1.json
rename to tests/snapshots/PEP 440/1.0.b1.json
index f8d7eb0..a0dec96 100644
--- a/tests/snapshots/unknown/1.0.b1.json
+++ b/tests/snapshots/PEP 440/1.0.b1.json
@@ -2,9 +2,9 @@
     "alpha": false,
     "beta": true,
     "dev": false,
-    "major": null,
+    "major": "1",
     "micro": null,
-    "minor": null,
+    "minor": "0",
     "modifier_type": "b",
     "modifier": "b1",
     "patch": null,
@@ -12,8 +12,8 @@
     "release_candidate": false,
     "sections": 2,
     "simple": false,
-    "strategy": "unknown",
+    "strategy": "PEP 440",
     "string": "1.0.b1",
-    "valid": false,
-    "year": null
+    "valid": true,
+    "year": "1"
 }
\ No newline at end of file
diff --git a/tests/snapshots/unknown/1.0.b2.json b/tests/snapshots/PEP 440/1.0.b2.json
similarity index 71%
rename from tests/snapshots/unknown/1.0.b2.json
rename to tests/snapshots/PEP 440/1.0.b2.json
index ea1492a..2c10d9a 100644
--- a/tests/snapshots/unknown/1.0.b2.json
+++ b/tests/snapshots/PEP 440/1.0.b2.json
@@ -2,9 +2,9 @@
     "alpha": false,
     "beta": true,
     "dev": false,
-    "major": null,
+    "major": "1",
     "micro": null,
-    "minor": null,
+    "minor": "0",
     "modifier_type": "b",
     "modifier": "b2",
     "patch": null,
@@ -12,8 +12,8 @@
     "release_candidate": false,
     "sections": 2,
     "simple": false,
-    "strategy": "unknown",
+    "strategy": "PEP 440",
     "string": "1.0.b2",
-    "valid": false,
-    "year": null
+    "valid": true,
+    "year": "1"
 }
\ No newline at end of file
diff --git a/tests/snapshots/unknown/1.0.d1.json b/tests/snapshots/PEP 440/1.0.d1.json
similarity index 71%
rename from tests/snapshots/unknown/1.0.d1.json
rename to tests/snapshots/PEP 440/1.0.d1.json
index 1226544..e4bf622 100644
--- a/tests/snapshots/unknown/1.0.d1.json
+++ b/tests/snapshots/PEP 440/1.0.d1.json
@@ -2,9 +2,9 @@
     "alpha": false,
     "beta": false,
     "dev": true,
-    "major": null,
+    "major": "1",
     "micro": null,
-    "minor": null,
+    "minor": "0",
     "modifier_type": "d",
     "modifier": "d1",
     "patch": null,
@@ -12,8 +12,8 @@
     "release_candidate": false,
     "sections": 2,
     "simple": false,
-    "strategy": "unknown",
+    "strategy": "PEP 440",
     "string": "1.0.d1",
-    "valid": false,
-    "year": null
+    "valid": true,
+    "year": "1"
 }
\ No newline at end of file
diff --git a/tests/snapshots/PEP 440/1.1-dev1.json b/tests/snapshots/PEP 440/1.1-dev1.json
new file mode 100644
index 0000000..6d29630
--- /dev/null
+++ b/tests/snapshots/PEP 440/1.1-dev1.json
@@ -0,0 +1,19 @@
+{
+    "alpha": false,
+    "beta": false,
+    "dev": true,
+    "major": "1",
+    "micro": null,
+    "minor": "1",
+    "modifier_type": "dev",
+    "modifier": "dev1",
+    "patch": null,
+    "prefix": null,
+    "release_candidate": false,
+    "sections": 2,
+    "simple": false,
+    "strategy": "PEP 440",
+    "string": "1.1-dev1",
+    "valid": true,
+    "year": "1"
+}
\ No newline at end of file
diff --git a/tests/snapshots/PEP 440/1.1_dev1.json b/tests/snapshots/PEP 440/1.1_dev1.json
new file mode 100644
index 0000000..d91cf83
--- /dev/null
+++ b/tests/snapshots/PEP 440/1.1_dev1.json
@@ -0,0 +1,19 @@
+{
+    "alpha": false,
+    "beta": false,
+    "dev": true,
+    "major": "1",
+    "micro": null,
+    "minor": "1",
+    "modifier_type": null,
+    "modifier": null,
+    "patch": null,
+    "prefix": null,
+    "release_candidate": false,
+    "sections": 2,
+    "simple": false,
+    "strategy": "PEP 440",
+    "string": "1.1_dev1",
+    "valid": true,
+    "year": "1"
+}
\ No newline at end of file
diff --git a/tests/snapshots/PEP 440/1_dev1.json b/tests/snapshots/PEP 440/1_dev1.json
new file mode 100644
index 0000000..b6439c1
--- /dev/null
+++ b/tests/snapshots/PEP 440/1_dev1.json
@@ -0,0 +1,19 @@
+{
+    "alpha": false,
+    "beta": false,
+    "dev": true,
+    "major": "1",
+    "micro": null,
+    "minor": null,
+    "modifier_type": null,
+    "modifier": null,
+    "patch": null,
+    "prefix": null,
+    "release_candidate": false,
+    "sections": 1,
+    "simple": false,
+    "strategy": "PEP 440",
+    "string": "1_dev1",
+    "valid": true,
+    "year": "1"
+}
\ No newline at end of file
diff --git a/tests/test_strategy.py b/tests/test_strategy.py
index edd16ae..d1fb8bc 100644
--- a/tests/test_strategy.py
+++ b/tests/test_strategy.py
@@ -47,6 +47,9 @@
                 "1.0.post456.dev34",
                 "1.0.post456",
                 "1.1.dev1",
+                "1.1-dev1",
+                "1.1dev1",
+                "1.1_dev1",
             )
         ],
         *[
diff --git a/tests/test_versions.py b/tests/test_versions.py
index c6fea72..4ce6548 100644
--- a/tests/test_versions.py
+++ b/tests/test_versions.py
@@ -59,6 +59,8 @@
     "1.0rc1.dev456",
     "1.0rc1",
     "1.1.dev1",
+    "1.1-dev1",
+    "1.1_dev1",
     "1.1",
     "1.2.3-1",
     "1.2.3-2",
@@ -77,6 +79,8 @@
     "1.8.2-beta.1.13",
     "1.dev0",
     "1.dev1",
+    "1-dev1",
+    "1_dev1",
     "1",
     "123",
     "2.0.0-alpha.1",