-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add an eval_int
command to the remote API and Python interface
#1660
Conversation
For now,
|
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.
Thanks, @chameco! I've left some minor suggestions inline, but otherwise this LGTM.
eval_size
seems trickier, and maybe not even useful in the Python setting right now, because as far as I know there is no way to define a Cryptol type value through the API (something like SAWScript's{| ... |}
).
Ah, good point. I do think we'll want to have a Python counterpart to {| ... |}
at some point, so it would be worth opening an issue about that. I agree that we don't need to solve that problem in this PR, however.
raise ValueError(str(v) + " is not an integer") | ||
return v | ||
|
||
def eval_bool(expr: cryptoltypes.CryptolJSON) -> int: |
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.
def eval_bool(expr: cryptoltypes.CryptolJSON) -> int: | |
def eval_bool(expr: cryptoltypes.CryptolJSON) -> bool: |
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.
It's curious that the Mypy run in CI didn't catch this. Testing locally: if I remove the isinstance
check, I get the expected type error ("returning Any from a function declared to return bool"), but I don't get any error if the isinstance
check mismatches the declared return type.
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.
A bool
is an int
:
>>> isinstance(False, int)
True
>>> isinstance(True, int)
True
>>> issubclass(bool, int)
True
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.
Ah, that would explain it. TIL. Thanks!
Also, can you update the changelogs for |
Partially addresses #1642. I'm marking this as a draft because I intend to add equivalents for other types (or maybe one
eval
command that works on everything) before merging.