Skip to content

[Bug]: Non-ASCII letters survive _sanitize_id, so get_parameter rejects the id it derives #17

Description

@fedonman

Bug Description

_sanitize_id replaces non-word characters using \W, which is Unicode aware, so letters and digits outside ASCII pass through untouched. Variable then checks the id against [A-Za-z_][A-Za-z0-9_]* and rejects it, so get_parameter raises InvalidVariableIdError instead of handing back a variable. The out[0].isdigit() guard has the same gap; it is true for ², and prefixing an underscore still leaves an id the pattern refuses. Switching the class to [^A-Za-z0-9_], or passing re.ASCII, fixes both.

Minimal Reproducible Example

import qprogram as qp
from qprogram.qprogram import _sanitize_id

print(_sanitize_id("drive_Ω"))   # 'drive_Ω', unchanged
qp.QProgram().get_parameter("drive", "Ω")

Expected Behavior

A sanitized id always matches [A-Za-z_][A-Za-z0-9_]*, so get_parameter returns a variable whatever the bus and parameter names look like.

Actual Behavior

File "src/qprogram/variable.py", line 273, in __init__
    raise InvalidVariableIdError(id)
qprogram.errors.InvalidVariableIdError: Variable id 'drive_Ω' is invalid: must match [A-Za-z_][A-Za-z0-9_]* (letters, digits, underscores only; cannot start with a digit, no spaces or special characters).

System Information

qprogram 0.1.0
python   3.14.3 | Linux-7.0.0-30-generic-x86_64-with-glibc2.43
vendors  none

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    builderTouches the QProgram builder: operations, blocks, fragments

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions