PPrevernal
Workflows

Coding workflows · Prerelease identifier precedence

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Prerelease identifier precedence

A concrete starting point
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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗