Skip to content

fix: use presence tests for loads() kwargs and reject invalid ones - #361

Open
ryanhill1 wants to merge 2 commits into
mainfrom
fix-loads-kwargs
Open

fix: use presence tests for loads() kwargs and reject invalid ones#361
ryanhill1 wants to merge 2 commits into
mainfrom
fix-loads-kwargs

Conversation

@ryanhill1

@ryanhill1 ryanhill1 commented Aug 7, 2026

Copy link
Copy Markdown
Member

Fixes #356

Six documented loads() kwargs were stored behind a walrus truthiness test (if dev_qbts := kwargs.get("device_qubits")), so any falsy caller value was silently treated as "not passed". Both adjacent gaps from the issue are closed as well:

  • unknown kwarg names (loads(src, devise_qubits=5)) raise TypeError
  • non-positive device_qubits / device_cycle_time / compiler_angle_type_size / frame_limit_per_port raise ValueError at load time, instead of surfacing later as a confusing validation message (an explicit None still means "not passed")

The kwarg→attribute map replaces the seven hand-written if blocks.

Also in this PR:

  • Stores explicitly provided None values for supported loads() kwargs in the load configuration.
loads() Kwarg Handling
sequenceDiagram
  participant T as tests/test_entrypoint.py
  participant E as entrypoint.py ⚠️
  T->>E: loads(src, **kwargs)
  E->>E: map kwargs to load attributes
  E->>E: validate provided values
  E-->>T: return loaded program or raise error
Loading

Auto-enriched by Argus

Six documented loads() kwargs were stored behind a walrus truthiness
test, so falsy caller values were silently discarded. All kwargs now use
presence tests; unknown kwarg names raise TypeError and non-positive
numeric values raise ValueError, so mistakes fail at the call site.

Fixes #356
@ryanhill1
ryanhill1 requested a review from TheGupta2012 as a code owner August 7, 2026 13:17
@argus-eye

argus-eye Bot commented Aug 7, 2026

Copy link
Copy Markdown

Argus review

Auto-review is off for this repo. Tick the box below to run a review on this PR.

  • Trigger Argus review

Estimated cost

  • Files changed: 3
  • Diff lines (±): 137
  • Historical avg: ~318.9k tokens · ~$1.35 · across last 6 review(s)

Tip: you can also comment @argus-eye review at any time.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: efcd85d7-f3a5-404f-8269-b63ee037e874

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ryanhill1

Copy link
Copy Markdown
Member Author

@Argus-Eye review

@argus-eye

This comment has been minimized.

@argus-eye argus-eye Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Argus · 9/10 — Loads kwargs validation is cleaner, with one compatibility warning to resolve

🔍 PR intent vs diff (LLM analysis)

Argus read the diff against the stated intent. This is not an execution log — reviewer still needs to test behavior.

Goal: Ensure loads() preserves falsy kwargs and rejects unknown or invalid values at the call site.
Stated acceptance criteria (from PR/issue — not independently verified):

  • All documented loads() kwargs are handled with presence tests so falsy values are preserved.
  • Unknown loads() kwarg names raise TypeError.
  • Non-positive device_qubits, device_cycle_time, compiler_angle_type_size, and frame_limit_per_port raise ValueError at load time.
  • An explicit None kwarg value is treated as not passed.
  • The kwarg-to-attribute map replaces the seven hand-written if blocks.

⚠️ Intent not delivered

Although src/pyqasm/entrypoint.py adds loads() kwarg handling and tests, finding 0 identifies that explicit None values are stored rather than treated as omitted. This fails the stated explicit-None acceptance criterion for API validation.

Unmet criteria:

  • An explicit None kwarg value is treated as not passed.

Verdict: This PR centralizes loads() kwarg handling, preserves falsy values, and adds call-site validation. It is close to merge-ready once the compatibility concern is addressed.

🟡 1 P1 · 3 files reviewed

Architecture: The map-based validation replaces repetitive branching cleanly; we should ensure its stricter behavior remains compatible with existing callers.

1 finding · 1 inline · 0 folded

🔢 81.0k tokens · $0.2005 total
Stage Tokens Cost
Intent 2.7k $0.0000
Triage 3.0k $0.0000
Lead agent 1.4k $0.0000
Review · bug_hunter 15.0k $0.0523
Review · security 14.9k $0.0451
Review · architecture 14.8k $0.0512
Review · regression 15.1k $0.0519
Review 11.3k $0.0000
Acceptance 1.0k $0.0000
Scoring 901 $0.0000
Synthesis 893 $0.0000

Contract: production/full · checked: bug_hunter, security, architecture, regression · review took 1m7s

Dashboard → · React 👎 to dismiss · Reply to any inline comment or use @argus-eye help to chat

Comment thread src/pyqasm/entrypoint.py Outdated
An explicit None no longer clobbers non-None defaults like
extern_functions={} or frame_in_def_cal=True.
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.

loads() silently drops falsy kwarg values (device_qubits=0, device_cycle_time=0.0, ...)

2 participants