Open the context
Choose the project folder and name the files or behavior involved.
Compare already-separated prerelease identifiers with numeric identifiers below text identifiers. Check multi-digit numbers, shared prefixes and stable-release empty tuples, rejecting leading-zero numbers and invalid identifiers.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import re
IDENT = re.compile(r"[0-9A-Za-z-]+")
def prerelease_cmp(left, right):
for item in (*left, *right):
if not isinstance(item, str) or not IDENT.fullmatch(item):
raise ValueError("identifier")
if item.isascii() and item.isdigit() and len(item) > 1 and item[0] == "0":
raise ValueError("leading zero")
if not left or not right:
return (not left) - (not right)
for a, b in zip(left, right):
if a == b: continue
an, bn = a.isdigit(), b.isdigit()
if an != bn: return -1 if an else 1
if an and len(a) != len(b): return (len(a) > len(b)) - (len(a) < len(b))
return (a > b) - (a < b)
return (len(left) > len(right)) - (len(left) < len(right))The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.