-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add panic
builtin function
#757
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #757 +/- ##
==========================================
- Coverage 93.00% 92.97% -0.04%
==========================================
Files 71 71
Lines 8178 8222 +44
==========================================
+ Hits 7606 7644 +38
- Misses 572 578 +6 ☔ View full report in Codecov by Sentry. |
|
||
vals = [ExprSynthesizer(self.ctx).synthesize(val)[0] for val in rest] | ||
node = PanicExpr(msg.value, vals) | ||
return with_loc(self.node, node), NoneType() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should panic
be generic over the type it returns? This would require also implementing check
to infer the return type.
Imo the proper way to implement this would be to use a bottom return type like Python's Never
or NoReturn
for panic
, but that's too much for this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't think of a good reason for panic returning anything other than None, do you think it is important?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, it's currently not possible to make the type checker understand that panics are an early exit. So, say you want to implement Option.unwrap
yourself, then you still need to explicitly return something in the error case:
def unwrap(opt: Option[T]) -> T:
match opt:
case Some(x): return x
case Nothing: return panic("Is None")
Co-authored-by: Mark Koch <[email protected]>
@mark-koch thanks for the fix! Feel free to approve if you are happy with the rest |
🤖 I have created a release *beep* *boop* --- ## [0.15.0](v0.14.0...v0.15.0) (2025-02-07) ### ⚠ BREAKING CHANGES * classical arrays can no longer be implicitly copied * `pytket` circuits no longer supported by `py` expressions (use `@pytket` or `load_pytket` instead) ### Features * add `panic` builtin function ([#757](#757)) ([4ae3032](4ae3032)) * Add array copy method ([#784](#784)) ([15bae6e](15bae6e)) * add boolean xor support ([#747](#747)) ([7fa4c8d](7fa4c8d)), closes [#750](#750) * Add CH gate to the stdlib ([#793](#793)) ([1199a14](1199a14)), closes [#792](#792) * Add string type ([#733](#733)) ([aa9341b](aa9341b)) * Array subscript assignment for classical arrays ([#776](#776)) ([6880e11](6880e11)) * Make `True` and `False` branches unconditional ([#740](#740)) ([748ea95](748ea95)) * Refactor to support affine arrays ([#768](#768)) ([92ec6d1](92ec6d1)) * Remove circuits from `py` expressions ([#746](#746)) ([ee8926b](ee8926b)) * support integer exponentiation in guppy source ([#753](#753)) ([70c8fcf](70c8fcf)) ### Bug Fixes * Allow string py expressions in result and panic ([#759](#759)) ([53401cc](53401cc)) * Fix error printing for structs defined in notebooks ([#777](#777)) ([b41e0fc](b41e0fc)) * Fix pytest hanging ([#754](#754)) ([9ad02bb](9ad02bb)) * panic on negative exponent in ipow ([#758](#758)) ([821771a](821771a)) * Properly report errors for unsupported subscript assignments ([#738](#738)) ([8afa2a9](8afa2a9)), closes [#736](#736) * remove newlines in extension description ([#762](#762)) ([2f5eed3](2f5eed3)) ### Documentation * remove broken link in README ([#801](#801)) ([fb1c3b5](fb1c3b5)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: hugrbot <[email protected]>
Closes #756