-
Notifications
You must be signed in to change notification settings - Fork 998
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
Replace assert
with custom require
method
#2366
Conversation
specs/phase0/beacon-chain.md
Outdated
#### `require` | ||
|
||
```python | ||
def require(condition: bool, message: str=None) -> None: |
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.
Strictly speaking, it should be Optional[str]
in Python:
def require(condition: bool, message: str=None) -> None: | |
from typing import Optional | |
def require(condition: bool, message: Optional[str]=None) -> None: |
- Python
Optional
might be confusing for the readers. AlthoughOptional
has been used in validator.md and das-core.md anyway... - mypy may raise an error if we use a stricter config
I'm fine either way 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.
We could force implicit optionals (https://mypy.readthedocs.io/en/stable/config_file.html#none-and-optional-handling) in the linter.ini
I started with |
All |
Curious what's the latest on this? Why do the specs still contain asserts instead of requires? |
Can't say I'm a member of the Dafny team, but I'm working on a transpiler from a subset of Python to Dafny.
See also the discussion in #1409 . It includes @franck44 's comment on how they deal with Hope that helps. |
Replace #2045
Fix #1797
Starting with
phase0/beacon-chain.md
Proposed solution
assert <condition>
with customrequire(condition: bool, message: str=None)
function to signal that the execution is INVALID. Implementers can define their custom error handling method.message
field./cc @ericsson49