Skip to content

fix: Implicit string concatenation in a list#1228

Open
odaysec wants to merge 1 commit intoamazon-braket:mainfrom
odaysec:patch-1
Open

fix: Implicit string concatenation in a list#1228
odaysec wants to merge 1 commit intoamazon-braket:mainfrom
odaysec:patch-1

Conversation

@odaysec
Copy link

@odaysec odaysec commented Mar 4, 2026

Description of changes:
fix this issue avoid relying on implicit concatenation when building a list of strings; instead, ensure each list element is a complete string and separated with a comma. In this specific case, the source="\n".join([...]) list should contain one element for the #pragma line and another element for the kraus(...) q[0] line, matching the surrounding pattern where each line of OpenQASM is a separate entry.

Concretely, in test/unit_tests/braket/circuits/test_circuit.py replace the two adjacent string literals:

"#pragma braket noise "
"kraus([[0.9486833im, 0], [0, 0.9486833im]], [[0, 0.31622777], "
"[0.31622777, 0]]) q[0]",

with two separate list elements by removing the implicit concatenation and making each line an explicit element separated by a comma:

"#pragma braket noise kraus([[0.9486833im, 0], [0, 0.9486833im]], [[0, 0.31622777], [0.31622777, 0]]) q[0]",

or, if the intent is to have the pragma and the kraus call on separate lines:

"#pragma braket noise",
"kraus([[0.9486833im, 0], [0, 0.9486833im]], [[0, 0.31622777], [0.31622777, 0]]) q[0]",

Given the existing OpenQASM pragma syntax already combines the directive and its argument on one line earlier in the file, the minimal change that preserves current behavior while removing implicit concatenation is to combine them into a single explicit string element.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@odaysec odaysec requested a review from a team as a code owner March 4, 2026 04:48
@rmshaffer
Copy link
Contributor

@odaysec thank you for the contribution! Could you say more about why implicit concatenation is bad in this case? Is it breaking a particular scenario? Would love to understand more about the reason for this change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants